var AbbA = (from t1 in mdc.table1
join t2 in mdc.table2 on t1.id equals t2.id
select new { t1, t2 }).AsQueryable();
if(a=1)
AbbA=AbbA.Where(q=>q.t1.cid==x);
else
AbbA=AbbA.Where(q=>q.t1.cid==y);
var Global=Abba.Select(q=> new{NewName1 = t1.field1, NewName2=t2.field2}).ToList();
我想只列出2個字段。但是返回了2個字段和where子句字段。Linq select返回where子句字段
探查視圖
exec sp_executesql N'SELECT
[Extent1].[cid] AS [cid], >>> This is where clause filed
[Extent1].[field1] AS [NewName1],
[Extent2].[field2] AS [NewName2]
FROM [dbo].[table1] AS [Extent1]
INNER JOIN [dbo].[table2] AS [Extent2] ON [Extent1].[id] = [Extent2].[id]
WHERE [Extent1].[cid] = @p__linq__0',N'@p__linq__0 int',@p__linq__0=10000
cid字段有聚簇(IX_INDEX)索引。因爲這個原因? – AbbA
這一行這裏將添加一個where子句AbbA = AbbA.Where(q => q.t1.cid == x); – orangesherbert