实体框架,其中列不相等

时间:2015-03-18 10:40:03

标签: c# asp.net-mvc entity-framework

我有以下查询

 var maListe = (from p in db.full
                       where ((p.acknowledge_by.Equals(..) && date>(new DateTime(2015,03,03)))

                       select new RequeteOptimise
                       {
                           objet = p.mc_object
                       }).ToList();

内部(...)我需要放一些不会影响查询的东西,结果应该就像我们运行这个查询一样

 var maListe = (from p in db.full
                       where ( date>(new DateTime(2015,03,03))

                       select new RequeteOptimise
                       {
                           objet = p.mc_object
                       }).ToList();

1 个答案:

答案 0 :(得分:1)

我会把它分开:

var queryBase = db.full.Where(p => date > (new DateTime(2015,03,03))).AsQueryAble();

然后如果你必须(例如在if块中)

queryBase = queryBase.Where(p => p.acknowledge_by.Equals( yourcriteria ));

然后实现:

var maListe = queryBase.Select(p => new RequeteOptimise{ objet = p.mc_object }).ToList();

一个Swing的替代方案:

var maListe = (from p in db.full
               where ( string.IsNullOrEmpty(yourcritera) || p.acknowledge_by.Equals(yourcriteria)) && date > new DateTime(2015,03,03)
               select new RequeteOptimise
               {
                   objet = p.mc_object
               }).ToList();