所以我有以下代码:
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调用,以减少冗余。最好的方法是什么?
最佳答案
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