【问题标题】:I have to select same projectId, Same resource Id rows from the database我必须从数据库中选择相同的 projectId、相同的资源 Id 行
【发布时间】:2021-01-05 08:24:22
【问题描述】:

我想从数据库中选择特定的 ResourceIdprojectId 行。 当传递一个包含一些 projectIdResourceId 的列表时,我得到一个错误:

LINQ to Entities 无法识别方法 'SyncRms.Services.RequiredData get_Item(Int32)' 方法,并且该方法无法转换为存储表达式。

代码:

for (int i = 1; i <= List.Count; i++)
{
    Guid RId = (Guid)List[i].ResourceId;

    // I get the error on this line of code
    var result = db.External_Timesheet.Where(x=>x.ResourceId.Equals(int(List[i].ResourceId))&&x.ProjectId.Equals(List[i].ProjectId));                          
 }

【问题讨论】:

    标签: c# list datatable where-clause


    【解决方案1】:

    Linq to Entities 不知道如何将 int 转换代码转换为 sql,您需要将其转换到 linq 查询之外,然后在查询中使用该值,对此的快速修复如下:

    int ResId = int(List[i].ResourceId);

    然后在你的查询中使用它

    x.ResourceId.Equals(ResId) ....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多