【发布时间】:2017-02-06 19:32:29
【问题描述】:
我有一个产品表:
产品编号
产品描述
类别编号
还有一个类别表:
类别 ID
分类说明
***对于每个产品,我想显示这样的一行:
产品 ID |产品描述 | 类别说明
我没有成功形成上述任务所需的必要映射。
产品映射我正在使用:
public ProductsMap()
{
Table("Products");
Id(x => x.ProductId);
Map(x => x.ProductDescription);
Map(x => x.CategoryId);
References(x => x.Categories)
.Column("CategoryId")
.Not.Nullable();
// Need Join() statement here?
...
我的产品类:
public class Products
{
public virtual int ProductId { get; set; }
public virtual string ProductDescription { get; set; }
public virtual int CategoryId { get; set; }
public virtual Category Category { get; set; }
public virtual int? CategoryDescription { get; set; } // Not in the db table.
}
我的目标是让 Fluent-NHibernate 通过指定的映射自动填充上述类中的 CategoryDescription 字段。
我使用了this answer 建议的join 语句,但以下语句出现了各种异常:
List<Products> products = session.Query<Products>().ToList();
注意:我可以从数据库中提取所有产品没有类别表中的相应列,所以我知道我的数据库连接性很好,并且应用程序的基本功能是健全的.
我是 Fluent-NHibernate 的新手,在这方面投入了相当多的时间,但我觉得我一无所获。我将不胜感激一些直接的指导。
【问题讨论】:
标签: c# orm fluent-nhibernate