【问题标题】:Query returns wrong result set - Entity Framework查询返回错误的结果集 - 实体框架
【发布时间】:2011-10-27 21:30:59
【问题描述】:

我正在使用实体框架 4.0。

客户是我的 ObjectContext 中的一个实体,而 Enity 类是自动生成的。我得到这样的客户:

Public Function GetAll(ByVal companyId As String) As System.Collections.Generic.IEnumerable(Of Customer) Implements ICustomerRepository.GetAll
    Return Me.objectSet.Where(Function(p) p.CompId = >companyId).AsEnumerable
End Function 

我的函数返回正确的结果集,但它并没有只选择 Comp.Id = conmpanyId 的客户。我也试过了

Return From p In Me.objectSet Where p.CompId = companyId Select p 

如何正确编写查询?

【问题讨论】:

    标签: entity-framework linq-to-entities


    【解决方案1】:

    我真的不知道VB的语法,但试试这个:

     Return Me.objectSet.Where(Function(p) p => p.CompId == companyId).AsEnumerable
    

    【讨论】:

      猜你喜欢
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      相关资源
      最近更新 更多