开发者

Fluent NHibernate delegate mapping Func

开发者 https://www.devze.com 2022-12-18 19:23 出处:网络
Given this (HORRIBLE) object graph that I can\'t change public class Email { public Email(string 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 IPer开发者_如何学Goson
{
    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...


Not sure about Fluent NHibernate, but you can create your own IUserType which will map from Email to string and vice versa. It's real easy: see this for an example.


It is called component and useful for mapping valuetypes like an emailaddress.

0

精彩评论

暂无评论...
验证码 换一张
取 消