在這裏,我不得不情況下得到的最新數據明智本月(即當前月)如何在OrderBy中使用Linq查詢結果?
Excepted Result
Date_time sum(collection.amountreceived) Sum(bank_deposit.depositamount)
1/07/2014 2000 1000
2/07/2014 3000 3000
架構
bank_deposit
agentid (nvarchar(30))
depositamount (DECIMAL(10,0))
date_time (TIMESTAMP)
collection
customeridn (varchar(30))
amountreceived (DECIMAL(10,0))
date_time (TIMESTAMP)
agentid (nvarchar(30))
在這裏,我用工會得到一列內datetime列數據
var unionDateColumn = ((from agent in db.collections select agent.Date_Time)
.Union(from u in db.bank_deposit select u.Date_Time)).ToList();
如何使用這個unionDateColumn數據orderby和獲得預期的輸出?
下面是量的總和的查詢,但在這裏我的問題是我如何
var model = (from coll in db.collections.Where(e => e.AgentID == item.AgentID)
let depositedAmount = db.bank_deposit.Where(d => d.AgentID == item.AgentID).Sum(c => c.DepositedAmount) == null ? 0
: db.bank_deposit.Where(d => d.AgentID == item.AgentID).Sum(x => x.DepositedAmount)
let collectionAmount = db.collections.Where(c => c.AgentID == item.AgentID).Sum(c => c.AmountReceived) == null ? 0
: db.collections.Where(v => v.AgentID == item.AgentID).Sum(m => m.AmountReceived)
select new GetBalanceAmount
{
DepositedAmount = depositedAmount,
CollectionAmount = collectionAmount
});
我有兩個表都有重複的數據,所以我在這裏用於date_time字段union現在unionDateColumn查詢returing兩列的日期(這是動態列)通過使用此列如何做orderby子句與下面的模型查詢得到預期產出? – user1983379