Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have two table with this sample data:

items:
itemID---MinStock
------------------
1 --- 100 
2 --- 5 
3 --- 20  
4 --- 10  


stock:
id---itemID---Qnty
------------------
1 --- 1    --- 5
2 --- 2    --- 10
3 --- 3    --- 5
4 --- 4    --- 10
5 --- 1    --- 7
6 --- 1    --- 20
7 --- 2    --- 5
8 --- 3    --- 25
9 --- 2    --- 5


how to get the sum value of the item if its sum Quantity less than MinStock (with entity framework).

What I have tried:

i don't have any idea to do it ..
Posted
Updated 10-Jun-18 22:41pm
v3
Comments
BillWoodruff 11-Jun-18 0:32am    
"i don't have any idea to do it .."

we can't read your mind. define your problem with much more detail. if an order for a quantity of an item exceeds the number of items in stock: that's an invalid order ... depending on policies.

1 solution

If i understand you well, you don't know how the get sum of Qnty field in stock table...
This is the way:
C#
var result = dbcontext.stock
    .GroupBy(x=>x.itemID)
    .Select(grp=>new
    {
        itemID = grp.Key,
        Count = grp.Sum(x=>x.Qnty)
    })
    .ToList();


The rest of job belongs to you!
 
Share this answer
 
v2
Comments
Golden Basim 11-Jun-18 8:37am    
this work , thanks
int Shortages_StockNoSer = nDB01.stock_noserials
.GroupBy(x => x.stitems_ID)
.Select(grp => new
{
itemID = grp.Key,
sum = grp.Sum(x => x.StockQnty),
min = grp.Select(s => s.st_items.stitems_MinBalance).FirstOrDefault()
}).Where(u => u.sum < u.min && u.min != 0)
.Count();
Maciej Los 11-Jun-18 8:58am    
You're very welcome!
Golden Basim 11-Jun-18 10:26am    
thank you bro ::

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900