FluentNHibernate 中的私有字段
我已配置 Fluent NHibernate 来映射项目中的实体。我的实体都没有公开公共属性(除了它们的 Id),它们的所有数据都存储在私有字段中。
通过使用:
public override bool ShouldMap(Member member)
{
return member.Name == "Id" || (member.IsPrivate && member.IsField);
}
它成功找到了我的字段,但随后期望我的数据库列被称为 _emailAddress 之类的名称。
如何将 _emailAddress 映射到名为 EmailAddress 的列?我的 SessionFactory 初始化如下所示:
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("AppConnection")))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<User>(new NHibMappingConfiguration())
.Conventions.Add(DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore))))
.CurrentSessionContext("web")
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
显然使用默认访问约定。
谢谢, 马特
I've configured Fluent NHibernate to map the entities in my project. None of my entities expose public properties (except their Id), all of their data is stored in private fields.
By using:
public override bool ShouldMap(Member member)
{
return member.Name == "Id" || (member.IsPrivate && member.IsField);
}
it successfully finds my fields, but then expects my database columns to be called things like _emailAddress.
How can I make it map _emailAddress to a column called EmailAddress? My SessionFactory initialisation looks like:
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("AppConnection")))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<User>(new NHibMappingConfiguration())
.Conventions.Add(DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore))))
.CurrentSessionContext("web")
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
using obviously a default access convention.
Thanks,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你在这里有几个选择。
1. 您可以创建自己的命名列约定(使用 INamingConvention 接口。请参阅此处)。
2. 您可以为各个类创建一个 MappingOverride 类,并为每个类定义列名:
i think you have a couple of options here.
1. you could create your own Convention for naming columns (use the INamingConvention interface. see here).
2. you could create a MappingOverride class for individual classes and define the column name for each one: