2017-02-15 87 views
2

所以我有以下代碼:如何將兩個實體框架調用合併爲一個?

var MAX_VOLUME = (from b in context.TRANSPORT_PLANNER_TRACK_CAP.Where(b => b.WAREHOUSE.Equals(warehouse)) select b.MAX_VOLUME).SingleOrDefault(); 
    var MAX_WEIGHT = (from b in context.TRANSPORT_PLANNER_TRACK_CAP.Where(b => b.WAREHOUSE.Equals(warehouse)) select b.MAX_WEIGHT).SingleOrDefault(); 
string maxVolume = MAX_VOLUME.ToString(); 
string maxWeight = MAX_WEIGHT.ToString(); 

我想這兩個語句合併成一個單一的EF電話,以減少冗餘。什麼是最好的方法?

回答

5
var result = (from b in context.TRANSPORT_PLANNER_TRACK_CAP 
       where b.WAREHOUSE.Equals(warehouse) 
       select new { b.MAX_VOLUME, b.MAX_WEIGHT}).SingleOrDefault(); 

然後就其引用爲:

result.MAX_WEIGHT or result.MAX_VOLUME 
相關問題