sum
複雑な環境で linq を使用するために助けが必要です
これはエンティティです
public class Product : EntityBase
{
[Key]
public int ProductId { get; set; }
public string Description { get; set; }
public string ReportText1 { get; set; }
public string ReportText2 { get; set; }
public bool Standard { get; set; }
public int ProductGroupId { get; set; }
public decimal? Surcharge1 { get; set; }
public decimal? Surcharge2 { get; set; }
public decimal? Surcharge3 { get; set; }
public decimal? Surcharge4 { get; set; }
public decimal PriceIn { get; set; }
public decimal PriceOut { get; set; }
public decimal PriceArtisanIn { get; set; }
public decimal PriceArtisanOut { get; set; }
public decimal PriceTotalIn { get; set; }
public decimal PriceTotalOut { get; set; }
public decimal PriceTotalOutVat { get; set; }
public decimal PriceAdjustment { get; set; }
public bool Calculate { get; set; }
public string Notes { get; set; }
public virtual ProductGroup ProductGroup { get; set; }
public virtual ICollection<ProductArticle> ProductArticles { get; set; }
}
public class ProductArticle : EntityBase
{
[Key]
public int ProductArticleId { get; set; }
public int ProductId { get; set; }
public int ArticleId { get; set; }
public decimal Qty { get; set; }
public decimal PriceIn { get; set; }
public bool Primary { get; set; }
public virtual Product Product { get; set; }
public virtual Article Article { get; set; }
}
public class Article : EntityBase
{
[Key]
public int ArticleId { get; set; }
public string ErpId { get; set; }
public string Supplier { get; set; }
public string Description { get; set; }
public string Specification { get; set; }
public string Unit { get; set; }
public string Account { get; set; }
public decimal PriceIn { get; set; }
public virtual ICollection<ArticleTime> ArticleTimes { get; set; }
}
public class ArticleTime : EntityBase
{
[Key]
public int ArticleTimeId { get; set; }
public int ArticleId { get; set; }
public int TimeId { get; set; }
public virtual Article Article { get; set; }
public virtual Time Time { get; set; }
}
public class Time : EntityBase
{
[Key]
public int TimeId { get; set; }
public int ArtisanId { get; set; }
public string Paragraph { get; set; }
public string Description { get; set; }
public string Unit { get; set; }
public decimal PriceIn { get; set; }
public bool System { get; set; }
public decimal Qty { get; set; }
}
製品から、時間内の合計数量が必要です。最初に Product から、すべての ProductArticle を反復し、Article 内で ArticleTime を反復し、次にこの内部で Time に移動し、これを合計します。
それとも、Product name TotalQty に新しい列を作成し、save メソッドで合計を行う方がよいでしょうか? 問題は、記事に時間を追加すると、製品エンティティが自動的に更新されないことです。何か案は?