在Linq-to-SQL表达式中使用多重选择

时间:2017-10-23 16:01:04

标签: c# entity-framework linq-to-sql asp.net-mvc-5 sqlgeography

我需要在视图中调用我的表中的模型+对象..如何添加变量TotalTime并将其插入到我的表中?

这是我的代码:

schoolinfo az = new schoolinfo();

var durer = 3;
var EstimationPrep = 20;

var  TotalTime = durer * az.Location.Distance(point) + EstimationPrep;

var places = (from u in context.schoolinfo 
              orderby u.Location.Distance(point)
              where u.Location.Distance(point) < DistanceMax
              select u).Take(10);
var nearschools = places.ToList();

return View(nearschools);

由于

1 个答案:

答案 0 :(得分:0)

它不完全清楚,但如果您只想将TotalTime添加到地方的每一行,您可以这样做:

var places = (from u in context.schoolinfo 
          orderby u.Location.Distance(point)
          where u.Location.Distance(point) < DistanceMax
          select new { u.column1, TotalTime }).Take(10);