流畅的nHibernate:如何保留用公式映射的属性?
我正在处理一个遗留数据库,并且我们有一个不再有意义的字段,但我不想更改数据库模式。
我正在尝试将旧的数据库文本字段映射到带有布尔值的类中(只需要了解数据库文本字段具有的一个选项)。我可以使用 Forumla 从数据库中获取布尔值,但我似乎可以让它将任何更新保存回数据库中。
我的课程和当前的流畅映射是:
public class Bulletin
{
public virtual int Id { get; set;}
public virtual bool RegularBulletin { get; set;}
}
public class BulletinMapping : ClassMap<Bulletin>
{
public BulletinMapping()
{
Table("Bulletins");
Id(x => x.Id, "ID").GeneratedBy.Identity();
Map(x => x.RegularBulletin)
.Formula("case when EmailType = 'BULLETIN_B' then 1 else null end")
.Nullable();
}
}
有人对如何保留 RegularBulletin 字段有任何想法吗?
谢谢 萨恩
I am dealing with a legacy database, and we have a field which doesn't make sense anymore, but I would rather not change the DB schema.
I'm trying to map an old DB text field into a class with a boolean (only need to know about one option that the DB text field has). I can get the boolean value out of the DB using Forumla, but I can seem to get it to save any updates back into the DB.
My class and current fluent mapping for it is:
public class Bulletin
{
public virtual int Id { get; set;}
public virtual bool RegularBulletin { get; set;}
}
public class BulletinMapping : ClassMap<Bulletin>
{
public BulletinMapping()
{
Table("Bulletins");
Id(x => x.Id, "ID").GeneratedBy.Identity();
Map(x => x.RegularBulletin)
.Formula("case when EmailType = 'BULLETIN_B' then 1 else null end")
.Nullable();
}
}
Does anyone have any ideas about how to persist the RegularBulletin field?
Thanks
Saan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用一个解决方法来解决这个问题 - 创建一个支持字段
受保护的虚拟字符串RegularBulletinString
并在其上使用布尔转换公式。I would use a workaround for this- create a backing field
protected virtual string RegularBulletinString
and use your boolean conversion formula on it.