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
.
精彩评论