为.NET项目选择数据库和ORM [英] Choosing Database and ORM for a .NET project

查看:192
本文介绍了为.NET项目选择数据库和ORM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端使用Silverlight的.NET应用程序。现在我来到这一点,我想在服务器端抛出我的静态伪数据,并添加一个数据库。

I'm working on a .NET application using Silverlight on the client side. Now I've come to the point where I want to throw out my static dummy data on the server side and add a database instead.

对于数据库,我喜欢使用其中一个ORM,我可以简单地标记我的模型类和数据库表是为我建立的。我之前用Groovy和Grails做了一些测试,认为GORM做了一个顺利的工作。在.Net中设置数据库的最好方法是什么?

For the database I'd love to use one of them ORM's where I can simply tag my model classes and the database tables are built for me. I did some tests with Groovy and Grails earlier, and thought GORM did a smooth job. What's the best way to set up a database in .Net?

我的第一件事是使用nHibernate。我真的不知道任何关于nHibernate,但我听说很多人热情地提到它。但是后来我看到ADO .Net也是一个ORM,它是内置的框架.. nHibernate outbeat ADO?与LINQ有什么协议?我看到它被列为一个ORM,但我虽然LINQ更多的查询部分?我可以通过LINQ定义数据库吗?

The first thing that strikes me is to use nHibernate. I don't really know anything about nHibernate, but I've heard numerous people mention it with enthusiasm. But then I see that ADO .Net also is an ORM, which is built into the framework.. Does nHibernate outbeat ADO? And what's the deal with LINQ? I see that's listed as an ORM too, but I though LINQ was more for the query part? Can I "define" the database through LINQ?

欢迎任何意见和建议。我也很愿意听到,如果你有什么数据库使用的意见。我认为MS SQL Server是最简单的选择?

Any comments and recommendations are welcome. I'd also love to hear if you have opinions on what database to use. I assume MS SQL Server is the easiest choice?

推荐答案

NHibernate和Silverlight

NHibernate贡献者之一,Ayende Rahien最近发布了关于NHibernate和Silverlight的博文

One of the NHibernate contributors, Ayende Rahien, recently posted a blog post about NHibernate and Silverlight:


我有一些关于NHibernate和Silverlight。这实际上是一个很容易回答的问题。

I got a few questions about NHibernate and Silverlight. That is actually a very easy thing to answer.

不要尝试。他们不相爱。事实上,他们甚至不会一起去。

Don’t even try. They don’t get along. In fact, they aren’t even going to get along.

Silverlight没有System.Data.IDbConnection,你可以放心地认为它有点重要NHibernate。

Silverlight doesn’t have System.Data.IDbConnection, and you can safely assume that that it somewhat important to NHibernate.

因此,在Silverlight应用程序中运行NHibernate,可能是为了访问本地数据库。但我不认为这是大多数人实际上想到的,当他们问关于NHibernate和Silverlight。他们想知道服务器上的NHibernate和客户端上的Silverlight。

So, running NHibernate inside a Silverlight application, presumably in order to access a local database is out. But I don’t think that this is what most people actually had in mind when they ask about NHibernate and Silverlight. They want to know about NHibernate on the server and Silverlight on the client.

这很容易回答,它会像任何客户端/服务器系统。所有相同的规则适用。因此,NHibernate应该工作,只要你不打算直接从Silverlight客户端使用它。所有相同的规则适用。

And that is easy enough to answer as well, it is going to work just like any client / server system. All the same rules apply.

NHibernate

NHibernate是一个非常好的ORM,学习曲线,所以你应该准备投入一些时间学习框架如果你选择NHibernate。

NHibernate is a great ORM but it has a quite steep learning curve, so you should be prepared to invest some time into learning the framework if you choose NHibernate. If you make that investment you will be rewarded by the flexibility and power that NHibernate provides.

Castle ActiveRecord

Castle ActiveRecord是一个构建在NHibernate之上的框架,因此与NHibernate非常相似。它减少了学习曲线,因为它增加了一些额外的抽象。顾名思义,它是用于与ActiveRecord模式一起使用的构建,并且包括一个基类,如果你不介意使用他们的ActiveRecord基类,它将提供很多功能。

Castle ActiveRecord is a framework that is build on top of NHibernate, and hence is quite similar to NHibernate. It reduces the learning curve a bit, since it adds some additional abstractions. As the name implies it is build for use with the ActiveRecord pattern, and includes a base class that gives you quite a lot of functionality if you don't mind using their ActiveRecord base class.

LINQ to SQL:

LINQ to SQL和ADO.NET实体框架是两个ORM: .NET Framework。 LINQ to SQL是一个比Entity Framework更小更简单的框架,但它有一些不错的功能,很容易开始使用。

LINQ to SQL and the ADO.NET Entity Framework are two ORM:s that are included in the .NET Framework. LINQ to SQL is a smaller and simpler framework than Entity Framework, but it has some nice features, and is quite easy to get started with.

实体框架:

Entity Framework很容易开始使用,但它在当前版本有一些相当大的问题,因为它仍然在版本但是,下一版本的Entity Framework将改进并修复当前的许多缺点。

Entity Framework is quite easy to get started with as well, but it has a few quite big problems in the current version, since it is still in version 1. However, the next version of Entity Framework will improve and fix many of the current shortcomings.

框架的LINQ和模式生成

所有这些框架都支持使用LINQ作为查询语言。 LINQ to SQL和NHibernate可以基于您的域类和映射为您生成模式。实体框架不能在v1中生成模式,但是v2将添加该功能。

All of these frameworks have support for using LINQ as the querying language. LINQ to SQL and NHibernate can generate a schema for you based on your domain classes and mapping. Entity Framework can not generate a schema in v1, but v2 will add that functionality.

这篇关于为.NET项目选择数据库和ORM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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