首页 新闻 赞助 找找看

Fluentnhibernate AutoMapping时如何设置主键和外键名称的生成规则

0
悬赏园豆:10 [已解决问题] 解决于 2012-02-22 13:15

如题

下面的是FluentNhibernate官方的文档,但是没有看到主键和外键生成规则的说明

http://wiki.fluentnhibernate.org/Available_conventions#ForeignKeyConvention

吕飞的主页 吕飞 | 菜鸟二级 | 园豆:280
提问于:2011-04-08 15:54
< >
分享
最佳答案
0

这里有的.http://wiki.fluentnhibernate.org/Fluent_mapping

内容如下,如需要翻译,请留言.

Id

Every mapping requires an Id of some kind. The Id is mapped using the Id method, which takes a lambda expression that accesses the property on your entity that will be used for the Id. Depending on the return type of the property accessed in the lambda, Fluent NHibernate will make some assumptions about the kind of identifier you're using. For example, if your Id property is an int, an identity column is assumed. Similarly, if you use a Guid then a Guid Comb is assumed.

Id(x => x.Id);

Note that the property you supply to Id can have any name; it does not have to be called "Id," as shown here.

That's the most common scenario for mapping your Id. Customisations can be done by chaining methods off the Id call. For example, if the column to which the Id property was to be mapped were not called Id, we could use the Column method to specify the name. For explicitly specifying the identity generator, you could use the GeneratedBy property.

Id(x => x.Id)
  .Column("PersonId")
  .GeneratedBy.Assigned();

In this example we're specifying that the Id property is mapped to a PersonId column in the database, and it's using an assigned generator.

Fluent NHibernate's interface is designed for discoverability. Everything you need should be easy to find "under" the declaring method using method chains.
收获园豆:10
DYStudio.Net | 小虾三级 |园豆:1747 | 2011-04-11 20:24
这个应该是用的Fluent Mapping,但是我用的是AutoMapping。
吕飞 | 园豆:280 (菜鸟二级) | 2011-04-12 09:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册