将现有表映射到 C# 中的域类
我什至不知道我是否使用了正确的术语,但这里是:
有没有一种方法可以通过工具或其他方式自动将 SQL Server 中的表及其关系映射到域(C# 代码)?
我使用了 nhibernate 插件,但它在 .cs 中创建一个文件,在 xml 中创建另一个文件,该文件具有映射,但我希望该映射在 .cs 文件中作为“属性”存在。
抱歉,如果这有点令人困惑。
I don't even know if I'm using the correct terms but here goes:
Is there a way to map the tables and their relations in a SQL Server to domain (C# code) automatically, by means of a tool or something?
I've used the nhibernate plugin, but it creates a file in .cs and another in xml, that has the mapping, but I want that mapping to be present as "property" in the .cs file.
Sorry if this is a bit confusing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您始终可以使用实体框架或者Linq2SQL,但我不熟悉它是如何工作的。
不过,在 EF 和 NHibernate 中,我更喜欢 NHibernate。
You could always use the Entity Framework or maybe Linq2SQL, but I'm not familiar with how that works.
Tho, out of EF and NHibernate, I prefer NHibernate.
使用 Linq 2 Sql 的 LLBLgen(VS 2008 中提供)。 或者使用实体框架(在 VS 2008 SP1 中)。
Linq 2 sql 允许您将表从 sql server 拖放到画布上,并为您创建一个域类,并将属性映射到列。
Use LLBLgen of Linq 2 Sql (available in VS 2008). Or use Entity Framework (in VS 2008 SP1).
Linq 2 sql allows you to drag and drop a table from sql server to the canvas and it creates a domain class for you with properties mapped to columns.
看一下 Fluent NHibernate,看看这是否是您正在寻找的:
http://blog.jagregory.com/2008/08/08 /介绍-Fluent-nhibernate/
Take a look at Fluent NHibernate and see if that is what you are looking for:
http://blog.jagregory.com/2008/08/08/introducing-fluent-nhibernate/
您可以使用使用属性的Castle ActiveRecord。
You can use Castle ActiveRecord which uses attributes.
我认为您应该阅读一些有关 Linq to Sql
http:// searchwindevelopment.techtarget.com/tip/0,289483,sid8_gci1269859,00.html#
I think you should read a bit about Linq to Sql
http://searchwindevelopment.techtarget.com/tip/0,289483,sid8_gci1269859,00.html#
查看 SubSonic。 它将生成您的 DAL,还可以根据自定义模板生成代码。
Check out SubSonic. It will generate your DAL and can also generates code off of custom templates.