考虑使用源自FormableEntity的QuotationForm,OrderForm和DeliveryForm,这是一个抽象类。 在QuotationForm中,我有一个QuotationLine的集合(ICollection)和其他字段。
public class QuotationEntity : FormableEntity, ISummable
{
double DiscountPercent { get; set; }
public ICollection<QuotationLineEntity> Lines { get; set; } = new List<QuotationLineEntity>();
public double Total
{
get
{
double PercentOfTotal = 1.0 - (DiscountPercent / 100.0);
return Lines.Aggregate(0.0, (sum, line) => sum + line.Total) * PercentOfTotal;
}
}
}
public class QuotationLineEntity : ISummable, IEntityBase
{
int LineNumber { get; set; }
string Description { get; set; }
int Quantity { get; set; }
double UnitPrice { get; set; }
string DeliveryTime { get; set; }
string Notes { get; set; }
Guid ReferencingLine { get; set; }
string ReferencingMainAppId { get; set; }
public double Total
{
get
{
return UnitPrice * Quantity;
}
}
public Guid Id { get; set; }
public DateTime DateCreated { get; set; }
public bool isActive { get; set; }
}
我有一个DbContext,到目前为止:
public DbSet<FormableEntity> Forms { get; set; }
public DbSet<QuotationLineEntity> QuotationLines { get; set; }
现在,在Repository中,我正在尝试根据其类型T
和Id:
IEnumerable<T> GetAll<T>(Guid id) where T : class, IEntityBase { WHAT SHOULD BE HERE? }
我试图检查类型并包含所需的容器,如下所示:
if(typeof(T) == typeof(QuotationEntity)){
var set = m_context.Set<QuotationEntity>.Where(f => f.Id == id);
}
但是,.Include
不起作用。
另外,我试图通用,所以考虑在OrderForm和DeliveryForm中使用OrderLines和DeliveryLines,以及所有Line实体(包括QuotationLine)的基类,这意味着public DbSet<QuotationLineEntity> QuotationLines { get; set; }
将更改为{ {1}}。我发现无法实现所需要的任何帮助吗?
答案 0 :(得分:1)
您需要将收藏品设为虚拟。如需进一步阅读,请使用此https://msdn.microsoft.com/en-us/data/jj574232(v=vs.113).aspx