我刚刚切换到 Fluent NHibernate,但遇到了一个问题,但没有找到任何相关信息。
情况如下:
public class Field : DomainObject, IField
{
public Field()
{
}
public virtual string Name { get; set; }
public virtual string ContactPerson { get; set; }
public virtual bool Private { get; set; }
public virtual IAddress Address { get; set; }
}
IAddress 是由一个名为 Address 的类实现的接口
public class Address : DomainObject, IAddress
{
public Address()
{
}
public virtual string City { get; set; }
public virtual string Country { get; set; }
public virtual string PostalCode { get; set; }
public virtual string StreetAddress { get; set; }
}
这是我的两个类的映射文件
地址
public class AddressMap : ClassMap<Address>
{
public AddressMap()
{
WithTable("Addresses");
Id(x => x.Id, "Id").Access.AsCamelCaseField(Prefix.Underscore).GeneratedBy.Guid();
Map(x => x.City, "City");
Map(x => x.Country, "Country");
Map(x => x.PostalCode, "PostalCode");
Map(x => x.StreetAddress, "StreetAddress");
}
}
场地
public class FieldMap : ClassMap<Field>
{
public FieldMap()
{
WithTable("Fields");
Id(x => x.Id, "Id").Access.AsCamelCaseField(Prefix.Underscore).GeneratedBy.Guid();
Map(x => x.Name, "Name");
Map(x => x.ContactPerson, "ContactPerson");
Map(x => x.Private, "Private");
References(x => x.Address, "AddressId").Cascade.Delete().Cascade.SaveUpdate();
}
}
因此,当我尝试从数据库中检索字段对象时,我收到 NHibernate 错误,指出 IAddress 未映射。有没有办法指定 NHibernate 在映射中使用 Address 类?
如果需要更多信息,请告诉我。
非常感谢,
查尔斯