查询动态Linq

时间:2014-04-03 11:14:25

标签: c# sql linq

我需要创建一个动态查询,其中变量DayOfWeek.Monday是动态的,我该如何设置?

DataClassesPDataContext pe = new DataClassesPDataContext();
var qry = from p in pe.R
          join q in pe.V on p.V equals q.V_
          where p.Data < data 
          where q.I == `v`
          where p.Data.DayOfWeek == `DayOfWeek.Monday`
          select(p.Q);

return qry.ToList().Average();

1 个答案:

答案 0 :(得分:2)

您可以将DayOfWeek提取到变量

var day = DayOfWeek.Monday;

var qry = ...
      where p.Data.DayOfWeek = day

但请注意。如果您对DayOfWeek

执行查询,则无法使用Entity Framework