我可以将什么 ORM 用于 Access 2007 - 2010?我在将 WPF 绑定到表格等之后 [英] What ORM can I use for Access 2007 - 2010? I'm after WPF binding to the tables etc

查看:18
本文介绍了我可以将什么 ORM 用于 Access 2007 - 2010?我在将 WPF 绑定到表格等之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个所有网站都有的旧数据库,它以多种类别/子类别/子项目格式描述特定内容.到目前为止,添加/编辑内容要么是在表中手动操作,要么是原始 sql Windows 窗体工具(我在开始工作时构建的!).

I've a legacy database that all sites have, it describes specific content in a number of catagory/subcatagory/child item format. Until now, adding/editing the content is either manual work in the tables OR raw sql Windows Forms tool (I built when I started out in the job!).

我想要使用 WPF 4.5 和 .net 4.5 的实体框架样式拖放、绑定和运行编码能力.

I would like Entity Framework style drag, drop, bind and run coding ability with WPF 4.5 and .net 4.5.

我对使用 NHibernate 犹豫不决,因为 EF5 使用起来非常简单,我理解 Nhibernate 的工作量更大(尽管是更快的 ORM).有没有效果很好的替代品?如果可能的话,我试图避免过多的手动设置.编辑器不是强制性项目,我无法证明在它上面进行大量额外工作是合理的 - 但如果将它的一个不错的版本放在一起,它将使我在接下来的两年中的工作更轻松.

I hesitate to use NHibernate as EF5 is very simple to get going with, I understand Nhibernate is more work (albeit a faster ORM). Are there alternatives that work well? I'm trying to avoid too much manual setup, if possible. The editor isn't a mandatory project and I can't justify lots of extra work on it - but it would make my job easier for the next 2 years if a nice version of it was put together.

所有反对 Access 的论点我都非常清楚:) - 至少在一年内都不能选择交换它.

All the argument against Access I know really well :) - swapping this isn't an option for at least a year.

搜索 StackOverflow 网站后,我没有看到太多问题要求这个,但如果我错过了一个好问题,我深表歉意!

Having searched the StackOverflow site, I don't see too many questions asking for this, but apologies if I've missed a good one!

更新:我想我应该稍微细化一下我的问题,因为我真正需要的是什么代码生成,这样我就不需要为 Access 数据库手动构建所有类.据我所知,Dapper 的工作是围绕效率,但与生成代码不同.来自实体框架的思维方式,我可以看到我在思考中将任务连接起来的地方:).所以除了煮我自己的 - 有没有人知道与 Access 一起使用的好的代码生成器.这我可以嫁给Dapper :)

Update: I think I should refine my question slightly as really what I needed to get at what code generation so that I don't need to hand build all the classes for the Access database. From what I can see, Dapper's work is around efficiency but is distinct from generating code. Coming from a entity framework mindset, I can see where I've conjoined the tasks somewhat in my thinking :). So apart from boil my own - does anyone know a good code gen for use with Access. This I can marry to Dapper :).

推荐答案

您不能使用实体框架,因为它不适用于 Access 数据库.

You can't use Entity Framework, because it doesn't work with Access databases.

可以将 NHibernate 与 MS Access 一起使用,尽管 NH 不支持开箱即用的 Access.
您需要 NHibernate.JetDriver 来自 NHContrib此处是 NH 配置文件的示例设置.

It's possible to use NHibernate with MS Access, although NH doesn't support Access out of the box.
You need NHibernate.JetDriver from NHContrib and here are example settings for the NH config file.

如果我没记错的话,NH Contrib 需要根据您使用的确切 NH 版本进行编译,因此您可能需要下载源代码并自行编译.

If I recall it correctly, NH Contrib needs to be compiled against the exact NH version you're using, so you probably need to download the source code and compile it by yourself.

作为替代方案,您可以使用众多微 ORM 之一,例如 Stack Overflow 自己的 Dapper.

As an alternative, you can use one of the many micro-ORMs, for example Stack Overflow's own Dapper.

Dapper 与数据库无关,因此它可以连接到包括 Access 在内的所有内容.引自官网:

Dapper is DB agnostic, so it can connect to everything including Access. Quote from the official site:

dapper 会与我的数据库提供商合作吗?
Dapper 没有特定于 DB 的实现细节,它适用于所有 .net ado 提供程序包括sqlite、sqlce、firebird、oracle、MySQL和SQL Server

Will dapper work with my db provider?
Dapper has no DB specific implementation details, it works across all .net ado providers including sqlite, sqlce, firebird, oracle, MySQL and SQL Server

缺点是因为 Dapper 是数据库不可知的,你必须自己实现一些高级的东西,比如 分页.

The disadvantage is that because Dapper is DB agnostic, you have to implement some advanved stuff yourself, like paging.

IMO Dapper 属于相当容易快速运行的类别".
看看这个:
(完整的演示项目在这里)

IMO Dapper is in the "fairly easy to run quickly catagory".
Take a look at this:
(complete demo project here)

using System;
using System.Data.OleDb;
using Dapper;

namespace DapperExample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"))
            {
                var list = con.Query<Product>("select * from products");

                Console.WriteLine("map to a strongly typed list:");
                foreach (var item in list)
                {
                    Console.WriteLine(item.ProductNumber + " : " + item.Description);
                }

                Console.WriteLine();

                var list2 = con.Query("select * from products");

                Console.WriteLine("map to a list of dynamic objects:");
                foreach (var item in list2)
                {
                    Console.WriteLine(item.ProductNumber + " : " + item.Description);
                }

                Console.ReadLine();
            }
        }
    }

    public class Product
    {
        public string ProductNumber { get; set; }
        public string Description { get; set; }
    }
}

此示例代码中有两个不同的查询.

There are two different queries in this example code.

第一个映射到强类型列表,例如结果是 IEnumerable.当然,它需要一个可以映射到的 Product 类.

The first one maps to a strongly typed list, e.g. the result is an IEnumerable<Product>. Of course it needs a Product class that it can map to.

第二个查询返回一个 IEnumerable<Dynamic> (>= .NET 4.0) 这意味着属性是动态评估的,你不需要之前定义一个类,但是缺点是你失去了类型安全(和智能感知).
我个人的观点是,缺少类型安全性对我来说是一个交易破坏者(我更喜欢第一个查询语法),但也许这适合你.

The second query returns an IEnumerable<Dynamic> (>= .NET 4.0) which means that the properties are evaluated on the fly and you don't need to define a class before, but the disadvantage is that you lose type safety (and IntelliSense).
My personal opinion is that the missing type safety is a deal breaker for me (I prefer the first query syntax), but maybe this is something for you.

这篇关于我可以将什么 ORM 用于 Access 2007 - 2010?我在将 WPF 绑定到表格等之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆