开发者

Fluent NHibernate: Mapping a nullable value-type property as a component

How can I map a nullable value-type property as a component in NHibernate?

For example:

public struct PersonName
{
    public st开发者_JAVA百科ring FirstName { get; private set; }
    public string LastName { get; private set; }

    public PersonName(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
}

public class Person
{
    public PersonName? Name { get; set; }
}

public class PersonDbMap : ClassMap<Person>
{
     public PersonDbMap()
     {
         /* This part doesn't compile! */
         Component(x => x.Name,
             part =>
             {
                 part.Map(x => x.FirstName, "FirstName");
                 part.Map(x => x.LastName, "LastName");
             }
     }
}


It's not possible to map a struct as a component.

You need to make it a class, or implement a IUserType.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜