问题描述
我有以下 5 个模型。我想在我的 ASP Core API 应用程序中使用 LINQ 将它们加入和分组。 我想加入我所有的 JournalVoucher、PurchaseInvoice 和 SaleInvoice 来计算一个项目的项目输入和输出以及剩余数量。请帮助我以最佳实践编写 LINQ 查询,
<Layout style={{ minHeight: "100vh" }}>
<Header>Header</Header>
<Content>Content</Content>
<Footer>Footer</Footer>
</Layout>
采购发票表
public partial class JournalVoucher : BaseEntity
{
//......
public DateTime VoucherDate{ get; set; }
public ICollection<Invoice> Invoices { get; set; }
public ICollection<PurchaseInvoice> PurchaseInvoices { get; set; }
}
销售发票表
public partial class PurchaseInvoice : BaseEntity
{
//...
public int Type{ get; set; }
public JournalVoucher JournalVoucher { get; set; }
public ICollection<PurchaseInvoiceLine> PurchaseInvoiceLines { get; set; }
}
public partial class PurchaseInvoiceLine : BaseEntity
{
//....
public int ItemId { get; set; }
public int UnitId { get; set; }
public decimal Quantity { get; set; }
public decimal discount { get; set; }
public decimal Tax { get; set; }
public PurchaseInvoice PurchaseInvoice { get; set; }
}
我的视图模型
public partial class SaleInvoice : BaseEntity
{
//...
public int Type{ get; set; }
public JournalVoucher JournalVoucher { get; set; }
public ICollection<SaleInvoiceLine> SaleInvoiceLines { get; set; }
}
public partial class SaleInvoiceLine : BaseEntity
{
//....
public int ItemId { get; set; }
public int UnitId { get; set; }
public decimal Quantity { get; set; }
public decimal discount { get; set; }
public decimal Tax { get; set; }
public SaleInvoice SaleInvoice { get; set; }
}
现在我想要通过使用 group by 连接这五个表来获得以下结果数据。
销售发票数量 = QuantityOut
采购发票数量= QuantityIn
public class ItemUsedInPurchaseAndInvoiceviewmodel
{
public int ItemId { get; set; }
public int UnitId { get; set; }
public decimal UnitPrice { get; set; }
public decimal discount { get; set; }
public decimal Tax { get; set; }
public decimal QuantityIn { get; set; }
public decimal QuantityOut { get; set; }
public DateTime VoucherDate{ get; set; }
public int Type{ get; set; }
public decimal TotalPriceIn => ((UnitPrice * QuantityIn - discount) + Tax);
public decimal TotalPriceOut => ((UnitPrice * QuantityOut - discount) + Tax);
public decimal TotalRemain => QuantityIn - QuantityOut;
}
解决方法
你可以做这样的例子:
m=mysql -p $password -h $host -u$user #you can also inline it of course
for i in `$m -e "show processlist" | awk '/$anySearchString/ {print $1}'`; do $m -e "call mysql.rds_kill($i);"; done