[英]combine two queries into one one query
I have two queries which both work but need to combine them into one working query 我有两个查询都可以工作,但需要将它们合并为一个工作查询
Query 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;
Query 2 查询2
var Props =
from n in db.tbl_Property.
Where(c => c.Prop_AvailableSpaces > 0)
select n;
Any help or advice welcome 欢迎任何帮助或建议
I would change those queries to pass in the original IQueryable<Property>
(or whatever the type is), then you can do: 我将这些查询更改为传入原始
IQueryable<Property>
(或任何类型),然后可以执行以下操作:
var advert = from m in source
where m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now
select m;
passing db.tbl_Property
in as the source
, then: 将
db.tbl_Property
作为source
传递,然后:
var Props = from n in filteredProperties
where n.Prop_AvailableSpaces > 0
select n;
ie composition 即组成
Do you mean something like: 您的意思是:
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);
Or perhaps combining with || 或与||组合 instead:
代替:
var advert = db.tbl_Property
.Where(m => (m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now)
|| m.Prop_AvailableSpaces > 0);
(Note that I haven't used a query expression here as you're only using a single where clause.) (请注意,由于您仅使用单个where子句,因此此处未使用查询表达式。)
Maybe something like this: 也许是这样的:
var advert =
from m in db.tbl_Property
where
(m.Prop_Update >= twoWeeksAgo && m.Prop_Update <= now)
|| (m.Prop_AvailableSpaces > 0)
select m;
var advert = db.tbl_Property.Where(m => m.Prop_Update >= twoWeeksAgo
&& m.Prop_Update <= now && m.Prop_AvailableSpaces > 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.