项目中用到Access数据库,之前用的普通Ado.Net 三层。遇到表字段叫多时,就比较费力。想要使用ORM,无奈EF不支持Access。虽然可以改写linq to sql为Linq to Access,多多少少会有些兼容性的问题。这有个demo:http://www.cnblogs.com/wangjikun3/archive/2009/06/20/1507175.html

这里推荐个ORM框架,DbEntry.Net.官网地址:http://dbentry.codeplex.com/

轻量级,高性能,免费开源。支持C#,Visual Basic,ASP.Net.也提供 DbEntryDataSource for ASP.NET 2.0和Rails风格 MVC框架和 简单的Ioc 框架.支持Access(03,07),SqlServer(2000,2005,2008),Excel,MySql,Sqlite,Oracle,Firebird,PostgreSQL.

官网文档:http://dbentry.codeplex.com/documentation

 

一.安装和简单使用

1.首先下载DbEntry.Net安装程序。官网下载:http://dbentry.codeplex.com/releases/view/79532 金山网盘:http://www.kuaipan.cn/file/id_226427209806521434.htm?source=1

  安装之后,打开VS,工具→扩展管理器→已安装的扩展→模板,启用DbEntryClassLibrary.

  如果不希望安装模板可以下载bin.zip。官网下载:http://dbentry.codeplex.com/releases/view/79532 金山网盘:http://www.kuaipan.cn/file/id_226427209806521433.htm?source=1

2.新建项目,点击Visual C#,选择DbEntryClassLibrary,输入项目名确定。会默认创建一个User类。删除我们创建个Student类。

  未安装模板需要引用dll:Lephone.Core.dll Lephone.Data.dll Lephone.Extra.dll Lephone.Web.dll

    public class Student : DbObjectModel<Student>
    {
        public string StuName { get; set; }
        public int StuAge { get; set; }
    }

 

3.新建Winform项目,添加对DbEntryClassLibrary项目引用。

  添加app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="Lephone.Settings"
      type="Lephone.Core.Setting.NameValueSectionHandler, Lephone.Core" />
  </configSections>
 
  <Lephone.Settings>
    <add key="AutoCreateTable" value="true" />
    <add key="DataBase" value="@Access : @C:\test.mdb" />
  </Lephone.Settings>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
XML Code

相关文章:

  • 2021-05-28
  • 2021-06-11
  • 2022-02-13
  • 2021-05-27
  • 2022-01-06
  • 2021-06-09
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2021-06-22
  • 2021-04-12
  • 2021-08-21
  • 2022-01-18
  • 2021-05-15
相关资源
相似解决方案