Fluent NHibernate 委托映射函数
鉴于这个(可怕的)对象图我无法更改,
public class Email
{
public Email(string email) { ... }
//DO a bunch of worthless stuff
}
public interface IPerson
{
Email Email{get;set;}
}
这样的东西存在吗?
Map(p => p.EmailAddress).Use(s => new EmailAddress(s));
本质上,Person 接口不会接受字符串,而且我不拥有 Email 类,所以我无法修改它......
Given this (HORRIBLE) object graph that I can't change
public class Email
{
public Email(string email) { ... }
//DO a bunch of worthless stuff
}
public interface IPerson
{
Email Email{get;set;}
}
Does something like this exist?
Map(p => p.EmailAddress).Use(s => new EmailAddress(s));
Essentially the Person interface won't take a string and I don't own the Email class so I can't modify it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定 Fluent NHibernate,但您可以创建自己的
IUserType
,它将从Email
映射到string
,反之亦然。这非常简单:请参阅此作为示例。Not sure about Fluent NHibernate, but you can create your own
IUserType
which will map fromEmail
tostring
and vice versa. It's real easy: see this for an example.它称为组件,对于映射值类型(如电子邮件地址)很有用。
It is called component and useful for mapping valuetypes like an emailaddress.