抽象クラスである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を持っている:
IEnumerable<T> GetAll<T>(Guid id) where T : class, IEntityBase { WHAT SHOULD BE HERE? }
:
public DbSet<FormableEntity> Forms { get; set; }
public DbSet<QuotationLineEntity> QuotationLines { get; set; }
さて、リポジトリで、私はそのタイプT
とIDに基づいてフォームを取得しようとしています
タイプを確認し、必要なコンテナを入れようとしました。
if(typeof(T) == typeof(QuotationEntity)){
var set = m_context.Set<QuotationEntity>.Where(f => f.Id == id);
}
ただし、.Include
は機能しません。 また、私は汎用的なので、OrderLineとDeliveryFormをOrderFormとDeliveryFormの中に入れ、すべてのLineエンティティ(QuotationLineを含む)の基本クラスを考えると、public DbSet<QuotationLineEntity> QuotationLines { get; set; }
はpublic DbSet<FormLineEntity> FormLines { get; set; }
に変わります。私は、何が必要なのか、何か助けを達成することは不可能だと思いますか?
ちょうど確かめて私が「仮想」権利としてそれをマークしているならば、包含は自動的になりますか? –
ええ、メカニズムは遅延ロードを呼び出します。レイジーローディングは、派生したプロキシタイプのインスタンスを作成し、仮想プロパティをオーバーライドしてロードフック –
を追加することで実現しますが、機能しません。 –