开发者

.Net Entity Framework - let keyword with a condition

I need to make a if-else statement in the query meaning I only want to add the OpenAmount to ExpectedAmount if the type = Cash, the problem is that it only gives me the cash row not the other row.

 Dim TenderList = (From t In EnData.BatchRecs 
                   Join b In EnData.RegShifts 
                   On t.BatchID Equals b.RegShiftID 
                   Where t.BatchID = ID 
                   Let ExpectedAmount = (t.ExpectedAmount + b.OpeningAmo开发者_JAVA技巧unt) 
                   Where t.TenderName = "CASH"
                   Select t.BatchRecID, ExpectedAmount, t.ExpectedCount, 
                      t.PickUpAmount, t.TenderName, OverShort, 
                      t.PickUpCount, t.TenderID)

Can this be done?


You should be able to use a conditional statement.

Let ExpectedAmount = If(t.TenderName = "CASH",
                        t.ExpectedAmount + b.OpeningAmount,
                        t.ExpectedAmount) 

You also don't need Where t.TenderName = "CASH" if you do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜