2016-10-20 5 views
0

抽象クラスである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; }に変わります。私は、何が必要なのか、何か助けを達成することは不可能だと思いますか?

答えて

1

コレクションを仮想化する必要があります。これ以上の読書のためにこれを使用するhttps://msdn.microsoft.com/en-us/data/jj574232(v=vs.113).aspx

+0

ちょうど確かめて私が「仮想」権利としてそれをマークしているならば、包含は自動的になりますか? –

+1

ええ、メカニズムは遅延ロードを呼び出します。レイジーローディングは、派生したプロキシタイプのインスタンスを作成し、仮想プロパティをオーバーライドしてロードフック –

+0

を追加することで実現しますが、機能しません。 –

関連する問題