Fluent NHibernate:将可为 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");
}
}
}
How can I map a nullable value-type property as a component in NHibernate?
For example:
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");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法将
struct
映射为组件。您需要将其设为一个类,或实现一个
IUserType
。It's not possible to map a
struct
as a component.You need to make it a class, or implement a
IUserType
.