【发布时间】:2019-05-26 11:22:46
【问题描述】:
我有Items 表:
Id Code Quantity
1 Cake01 10
2 Cake02 15
3 Cake03 20
public class Items
{
public int Id { get; set; }
public string Code { get; set; }
public int Quantity { get; set; }
}
Orders 表:
Id ItemsId Quantity
1 1 5
2 1 3
3 2 10
4 3 2
5 3 5
6 1 2
public class Orders
{
public int Id { get; set; }
public int ItemsId { get; set; }
public virtual Items Items { get; set; }
public int Quantity { get; set; }
}
如何在 MVC 5 中获得剩余数量?通常,我只是创建这样的视图:
select a.Id, a.Quantity-(isnull(b.Quantity,0)) as Remaining
from Items a left join
(select ItemsId as Id, sum(Quantity) as Quantity group by ItemsId) as b
on a.Id = b.Id
结果:
Id Remaining
1 1
2 5
3 10
是否可以在 MVC 5 中创建非持久性字段?我对此进行了搜索,但一无所获。
【问题讨论】:
标签: c# sql-server asp.net-mvc-5 ef-code-first