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

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

问题描述

我有一个所有网站的遗留数据库,它描述了一些catagory / subcatagory /子项目格式的具体内容。到目前为止,添加/编辑内容是手动工作在表或原始的sql Windows窗体工具(我在工作开始时创建。)



我想要实体框架样式拖放,删除,绑定和运行编码能力与WPF 4.5和.net 4.5。



我不犹豫使用NHibernate作为EF5是很容易去与,我明白Nhibernate是更多的工作(虽然更快的ORM)。有没有可行的替代品?我想尽量避免太多的手动设置。编辑器不是一个强制性的项目,我不能证明很多额外的工作,但它会使我的工作更容易在未来的2年,如果一个不错的版本放在一起。



对Access的所有参数我知道真的很好:) - 交换这不是一个选项至少一年。



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



感谢您提供的任何建议!



更新:我想我应该稍微改进我的问题,代码生成,使我不需要手工构建Access数据库的所有类。从我可以看到,Dapper的工作是围绕效率,但不同于生成代码。来自一个实体框架的心态,我可以看到我在我的想法在某种程度上结合了任务。所以除了boil我自己 - 有没有人知道一个良好的代码gen用于Access。

解决方案

您不能使用Entity Framework,因为它不能使用Access数据库。



可以使用NHibernate与MS Access,虽然NH不支持Access开箱。

您需要 NHibernate.JetDriver NHContrib 此处是NH配置文件的示例设置。



如果我记得正确,NH Contrib需要根据您正在使用的NH版本进行编译,您可能需要自己下载源代码并自己编译。



或者,您可以使用许多微型ORM之一,例如Stack Overflow自己的< a href =http://code.google.com/p/dapper-dot-net/ =nofollow> Dapper 。



Dapper是DB不可知的,所以它可以连接到一切,包括Access。从官方网站引用:


Will dapper可以与我的数据库提供商配合使用吗?

Dapper没有DB特定的实现细节,它适用于所有.net ado提供程序
包括sqlite,sqlce,firebird,oracle,MySQL和SQL Server


缺点是,因为Dapper是DB不可知的,你必须自己实现一些优点,比如分页






编辑



<

看看这个:

=https://bitbucket.org/christianspecht/code-examples/src/tip/DapperExample?at=default =nofollow>此处完成演示项目

 使用System; 
using System.Data.OleDb;
using Dapper;

命名空间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(映射到强类型列表:);
foreach(列表中的var项)
{
Console.WriteLine(item.ProductNumber +:+ item.Description);
}

Console.WriteLine();

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

Console.WriteLine(映射到动态对象列表);
foreach(list2中的var项)
{
Console.WriteLine(item.ProductNumber +:+ item.Description);
}

Console.ReadLine();
}
}
}

public class Product
{
public string ProductNumber {get;组; }
public string描述{get;组; }
}
}

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



第一个映射到强类型列表,例如结果是 IEnumerable< Product> 。当然,它需要一个产品类,它可以映射到。



第二个查询返回 IEnumerable< Dynamic> (> = .NET 4.0),这意味着属性在运行时被评估,你不需要定义一个类,但缺点是你失去类型安全性(和智能感知)。

我个人认为缺少的类型安全性对我来说是一个交易断路器(我更喜欢第一个查询语法),但也许这是给你的。


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!).

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

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.

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

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

Thank you for any advice rendered!

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 :).

解决方案

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

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.

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.

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

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

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

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


EDIT:

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.

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.

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天全站免登陆