当我们选择新对象时,如何将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'未在当前范围内声明或未声明
谢谢。
答案 0 :(得分:1)
通过声明预期的类型使表达式具体化。 Where子句在Select语句之前。 query
是Anonymous 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}