我想将此查询转换为LINQ或使用lambda表达式
ALTER procedure [dbo].[grid_data]
@fromdate datetime,
@todate datetime,
@region varchar(50)
as
Select D.ID as ID, D.OName,
(Select Count(*) from tblve WHERE MID = D.ID and Vme <> ''),
D.Mil,D.Speed
from tblRe M
inner join tblReg D
On M.RID = D.RID
我尝试了这种方法,但在计数时显示错误
[WebMethod]
public static string search_data(DateTime fromdate, DateTime todate, string region)
{
try
{
T1 ts = new T1();
var query = (from M in ts.tblRe
join D in ts.tblReg on M.RID equals D.RID
where
M.Region == region
&& M.StartDate <= fromdate
&& M.EndDate >= todate
select new {
D.ID,
D.OName,
Count = ts.tblve.Where(x => x.MID == D.ID && x.Vme !=
'').Count()
D.Mil,
D.Speed
}).ToList();
这显示错误空字符文字在这条线上'')
这个解决方案怎么样:
var query = from M in context.tblRe
join D in context.tblReg on M.RID equals D.RID
where M.StartDate <= fromdate && M.EndDate >= todate && M.region == region
select new {
D.ID,
D.OName,
Count = context.tblve.Where(x => x.MID == D.ID && x.Vme != "").Count()
D.Mil,
D.Speed
};