我有这 2 节课
public class Product {
public virtual Guid Id {get; set;}
public virtual string Name {get; set;}
public virtual Description Description {get; set;}
}
public class Description {
public virtual Guid Id {get; set;}
public virtual string Suggestion {get; set;}
public virtual string Composition {get; set;}
}
我尝试使用此 Mapper 类映射该类:
public class ProductMap : ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name);
References(x => x.Description).ForeignKey("Id");
}
}
描述与具有相同 Id 的产品相关,因此例如 Id = 1 的产品将在 Id = 1 的表中具有描述。现在我尝试从表中读取数据:
using (var session = factory.OpenSession())
{
var testProduct = session.Query<Product>().Where(p => p.Id == 2).Single();
lblValue.Text = testProduct.Description.Composition;
}
但我得到错误异常
InnerException: System.Data.SqlClient.SqlException
Message=Invalid column name 'Description_id'.
我知道我在映射器构造函数中出错了。你们能帮我如何正确映射它。我不想将字段 Description_id 放在表产品中。谢谢