我能在我的网域逻辑NHibernate的映射文件和数据库结构? [英] How can I generate NHibernate mapping files and DB constructs from my domain logic?

查看:167
本文介绍了我能在我的网域逻辑NHibernate的映射文件和数据库结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要落实在我的项目我的域对象NHibernate的,但我不知道我应该怎么去生成映射文件和数据库。

I want to implement NHibernate on my domain objects in my project, but I'm not sure how I should go about generating the mapping file, and the database.

我发现一些问题,那种淡淡的这个这里和< A HREF =http://stackoverflow.com/questions/183586/tool-for-generating-c-classes-from-nhibernate-mappings-files>这里,但我开始与我的课已经定义的,并想从他们开始,然后我一路下跌,而不是其他的方式。

I've found some questions that kind of touch on this here and here, but I'm starting with my classes already defined, and would like to start from them and work my way down, not the other way around.

有没有办法做到这一点?

Is there any way to do this?

我是一个多阶段过程完全没有问题,我只是想知道别人怎么做,这是成功的他们。

I'm perfectly fine with a multi-stage process, I just want to know what other people have done that was successful for them.

仅供参考,我想部署SQL Server 2005的数据库

FYI, I want to deploy the database on SQL Server 2005.

推荐答案

关于映射:
可以创建像加里流利的映射的映射。
如果你有一个非常简单的领域模型,你可以使用自动映射,FluentNhibernate的公约基于映射功能:

About the mapping: You can create the mapping with the Fluent Mapping like Gary. When you have a very uncomplicated domain model, you can use Automapping, a convention based mapping feature of FluentNhibernate:

 var sessionFactory = Fluently.Configure()  
   .Database(MsSqlConfiguration.MsSql2005  
     .ConnectionString(c => c  
       .Is(ApplicationConnectionString)))  
   .Mappings(m =>  
     m.AutoMappings.Add(AutoPersistenceModel.MapEntitiesFromAssemblyOf<Product>())  
   )  
   .BuildSessionFactory();



这就是你所需要的。

And that's all you need.

你可以建立的SchemaExport数据库:

You can build your database with schemaexport:

var schemaExport = new SchemaExport(configuration);
schemaExport.Create(false,true);

这篇关于我能在我的网域逻辑NHibernate的映射文件和数据库结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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