尝试使用两个相同的子类映射Order Class并获得以下错误
Could not find a getter for property 'RatingCriteria1' in class 'ORM.Entities.Enquiry.EnquiryOrder'
基本上我在数据库中有一个表有很多列。 12列与评级相关
BuyerRatingCriteria1,BuyerRatingCriteria2,BuyerRatingCriteria3,BuyerRatingCriteria4,BuyerRatingCriteria5,BuyerRatingCriteriaComments
和
SupplierRatingCriteria1,SupplierRatingCriteria2,SupplierRatingCriteria3,SupplierRatingCriteria4,SupplierRatingCriteria5,SupplierRatingCriteriaComments
我想将这些简化为两个子类,以便我有
Order.SupplierRating.Criteria1
和
Order.BuyerRating.Criteria1
例如
public class EnquiryOrder : Entity
{
public virtual int Id { get; set; }
public virtual DateTime DateOrdered { get; set; }
public virtual string PONumber { get; set; }
public virtual string SONumber { get; set; }
public virtual Rating SupplierRatings { get; set; }
public virtual Rating BuyerRatings { get; set; }
}
public class Rating : Entity
{
public virtual int RatingCriteria1 { get; set; }
public virtual int RatingCriteria2 { get; set; }
public virtual int RatingCriteria3 { get; set; }
public virtual int RatingCriteria4 { get; set; }
public virtual int RatingCriteria5 { get; set; }
public virtual string RatingCriteriaComment { get; set; }
}
映射我认为就像这个
一样简单 public EnquiryOrderMapping()
{
Id(x => x.Id).Column("EnquiryOrderId");
Map(x => x.DateOrdered);
Map(x => x.PONumber).Nullable();
Map(x => x.SONumber).Nullable();
Map(x => x.BuyerRatings.RatingCriteria1).Column("EnquiryBuyerRatingsRatingCriteria1").Nullable();
Map(x => x.BuyerRatings.RatingCriteria2).Column("EnquiryBuyerRatingsRatingCriteria2").Nullable();
Map(x => x.BuyerRatings.RatingCriteria3).Column("EnquiryBuyerRatingsRatingCriteria3").Nullable();
Map(x => x.BuyerRatings.RatingCriteria4).Column("EnquiryBuyerRatingsRatingCriteria4").Nullable();
Map(x => x.BuyerRatings.RatingCriteria5).Column("EnquiryBuyerRatingsRatingCriteria5").Nullable();
Map(x => x.BuyerRatings.RatingCriteriaComment).Column("EnquiryBuyerRatingsRatingCriteriaComment").Nullable();
}
不,我没有忘记在这里映射供应商方面,因为我试图最大限度地简化它以便能够解决它。
所以我不明白为什么会出现问题...我已经告诉它要查看哪一列(全名)而不是“RatingCriteria1”
以及当我有一个变量RatingCriteria1时,它有一个getter和setter !!!
非常奇怪......我错过了映射这样的子类时你必须要做的事情吗?
答案 0 :(得分:0)
您需要将评分作为一个组件映射,方法如下:
public EnquiryOrderMapping()
{
Id(x => x.Id).Column("EnquiryOrderId");
Map(x => x.DateOrdered);
Map(x => x.PONumber).Nullable();
Map(x => x.SONumber).Nullable();
Component(x => x.BuyerRatings,
y =>
{
y.Map(r => r.RatingCriteria1, "EnquiryBuyerRatingsRatingCriteria1").Nullable();
y.Map(r => r.RatingCriteria2, "EnquiryBuyerRatingsRatingCriteria2").Nullable();
y.Map(r => r.RatingCriteria3, "EnquiryBuyerRatingsRatingCriteria3").Nullable();
// etc..
});
// etc..
}