【问题标题】:Select a new object including a where选择一个包含 where 的新对象
【发布时间】:2014-10-30 19:46:01
【问题描述】:

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

这是我所拥有的:

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”要么未声明,要么不在当前范围内

谢谢。

【问题讨论】:

  • 先使用where子句
  • 你还需要一个变量来接受表达式:Dim query = From...

标签: .net vb.net linq


【解决方案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} 

【讨论】:

    猜你喜欢
    • 2017-09-24
    • 2010-12-18
    • 2022-01-15
    • 2014-12-16
    • 2019-12-22
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 2020-07-20
    相关资源
    最近更新 更多