如何将可以为null的值类型属性映射为NHibernate中的组件?
例如:
public struct PersonName
{
public string 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");
}
}
}
答案 0 :(得分:4)
无法将struct
映射为组件。
您需要将其设为类,或实现IUserType
。