Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用表1中的字段查找表2并从表2中检索列数据?_C#_Linq - Fatal编程技术网

C# 如何使用表1中的字段查找表2并从表2中检索列数据?

C# 如何使用表1中的字段查找表2并从表2中检索列数据?,c#,linq,C#,Linq,我在varialble SI中有一个如下所示的对象数组。我正在尝试使用SoftwareImageId查找另一个表ods.tblSoftwareImages,并从表ods.tblSoftwareImages中获取所有softwareimages的列表。有人能提供如何做到这一点的指导吗 SIs [ { "ProductLineID": 17646, "SoftwareImageId": 17646, "SoftwareProductId": "2032882" },

我在varialble SI中有一个如下所示的对象数组。我正在尝试使用
SoftwareImageId
查找另一个表
ods.tblSoftwareImages
,并从表
ods.tblSoftwareImages
中获取所有
softwareimages
的列表。有人能提供如何做到这一点的指导吗

SIs
[
  {
    "ProductLineID": 17646,
    "SoftwareImageId": 17646,
    "SoftwareProductId": "2032882"
  },
  {
    "ProductLineID": 17646,
    "SoftwareImageId": 17646,
    "SoftwareProductId": "2032881"
  },
  {
    "ProductLineID": 17645,
    "SoftwareImageId": 17645,
    "SoftwareProductId": "2032883"
  }
]

public IEnumerable<SoftwareImage> GetSIForSP(int SoftwareProductID)
{
    var SIs = _entities.tblSoftwareProductSoftwareImages
        .Where(x =>x.SoftwareProductId == SoftwareProductID).ToList();
    return null;
}
SIs
[
{
“ProductLineID”:17646,
“SoftwareImageId”:17646,
“软件产品ID”:“2032882”
},
{
“ProductLineID”:17646,
“SoftwareImageId”:17646,
“软件产品ID”:“2032881”
},
{
“ProductLineID”:17645,
“SoftwareImageId”:17645,
“SoftwareProductId”:“2032883”
}
]
公共IEnumerable GetSIForSP(int-SoftwareProductID)
{
var SIs=\u entities.tblSoftwareProductSoftwareImages
.Where(x=>x.SoftwareProductId==SoftwareProductId).ToList();
返回null;
}

您可以从SIs中选择ImageID,并在images表中查询这些ID。 示例代码:我不知道表的名称以及Id属性的外观

public IEnumerable<SoftwareImage> GetSIForSP(int SoftwareProductID)
{
    var imageIds = _entities.tblSoftwareProductSoftwareImages
        .Where(x =>x.SoftwareProductId == SoftwareProductID)
        .Select(x=>x.SoftwareImageId)
        .ToList();
    var images = _entities.tblSoftwareImages
                            .Where(x=>imageIds.Contains(x.SoftwareImageId));
    return images;
}
public IEnumerable GetSIForSP(int-SoftwareProductID)
{
var imageIds=_entities.tblSoftwareProductSoftwareImages
.Where(x=>x.SoftwareProductId==SoftwareProductId)
.选择(x=>x.SoftwareImageId)
.ToList();
var images=\u entities.tblSoftwareImages
。其中(x=>ImageID.Contains(x.SoftwareImageId));
返回图像;
}

返回
null
可能无法满足您的需求。您是否要求为每个
SoftwareImageId
返回
SoftwareImage
(显然是
ods.tblSoftwareImages
表中的一个字段)的SQL查询?Jim-您的理解是对的,这正是我正在寻找的,它是否需要在数组中?您可以创建一个类并将其放入列表中。输入是一个对象数组,我们需要返回软件映像列表。您可以将您的数组转换为一个对象列表,获取当前数据库对象,并在两个列表上进行联接,以获取数据吗?