选择一个包含where的新对象

时间:2014-10-30 19:46:01

标签: .net vb.net linq

当我们选择新对象时,如何将Where Linq 一起使用?

这就是我所拥有的:

From x In mydb.vw_TransactionsWithNames 
Select New datetransaction() With {.start = x.StartDate, .ends = x.EndDate} 
Where x.fkCommunity = c.PkCommunity And x.isCancelled = 0

但我在Select New datetransaction() With {.start = x.StartDate, .ends = x.EndDate} - >之后出错了姓名' x'未在当前范围内声明或未声明

谢谢。

1 个答案:

答案 0 :(得分:1)

通过声明预期的类型使表达式具体化。 Where子句在Select语句之前。 queryAnonymous Type,是结果的集合。

Dim query = From x As {datatype here} In mydb.vw_TransactionsWithNames 
            Where x.fkCommunity = c.PkCommunity And x.isCancelled = 0
            Select New With {.start = x.StartDate, .ends = x.EndDate}