1

我有两个查询都可以工作,但需要将它们组合成一个工作查询

查询 1

  var now = DateTime.Now;
  var twoWeeksAgo = now.AddDays(-14);

  var advert =
      from m in db.tbl_Property
      where m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now
      select m;

查询 2

  var Props = 
      from n in db.tbl_Property.
      Where(c => c.Prop_AvailableSpaces > 0)
      select n;

欢迎任何帮助或建议

4

4 回答 4

3

我会更改这些查询以传递原始查询IQueryable<Property>(或任何类型),然后您可以执行以下操作:

var advert = from m in source
             where m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now
             select m;

db.tbl_Property作为传入source,则:

var Props = from n in filteredProperties
            where n.Prop_AvailableSpaces > 0
            select n;

即组成

于 2012-04-25T07:38:32.453 回答
2

你的意思是这样的:

var now = DateTime.Now;
var twoWeeksAgo = now.AddDays(-14);

var advert = db.tbl_Property
               .Where(m => m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now
                           && m.Prop_AvailableSpaces > 0);

或者也许结合 || 反而:

var advert = db.tbl_Property
               .Where(m => (m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now)
                           || m.Prop_AvailableSpaces > 0);

(请注意,我在这里没有使用查询表达式,因为您使用了一个 where 子句。)

于 2012-04-25T07:38:17.763 回答
0

也许是这样的:

var advert =
            from m in db.tbl_Property
            where 
                (m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now)
                || (m.Prop_AvailableSpaces > 0)

            select m;
于 2012-04-25T07:37:57.970 回答
0
     var advert = db.tbl_Property.Where(m => m.Prop_Update >= twoWeeksAgo 
     && m.Prop_Update <= now && m.Prop_AvailableSpaces > 0);
于 2012-04-25T07:39:20.720 回答