连接2个表并在LINQ中返回多行

时间:2015-02-08 22:25:42

标签: join

我们有两个表.Equipment_Table和PicturesOfEquipment_Table。 我想提供设备的详细信息,以及第二张表返回设备的照片。 Equipment_Table:EqID,TitleOfEquipment,Comment PicturesOfEquipment_Table:PicID,EqID,PictureName 功能是:

public List<object> Return_Equipment(long GroupCode)
    {
        var td = from s in Entity.Equipment_Table 
                 join r in Entity.PicturesOfEquipment_Table on s.EqID equals r.EqID 
                 where s.ServiceGroupCode == GroupCode
                 select s;


        return td.ToList();
    }

但是td.ToList()发生错误。 无法隐式转换类型&#39; System.Collections.Generic.List&#39;到&#39; System.Collections.Generic.List&#39;

1 个答案:

答案 0 :(得分:0)

只需:

public List<object> Return_Equipment(long GroupCode)
    {
        var td = from s in Entity.Equipment_Table 
                 join r in Entity.PicturesOfEquipment_Table on s.EqID equals r.EqID 
                 where s.ServiceGroupCode == GroupCode
                 select s;


        return td;
    }