0

执行以下代码时

    public static List<Filmler> GetPlayerByMovie(int id)
    {
        var data = from o in db.Oyuncular
                   where o.OyuncularID == id
                   select o;

        return data.ToList();
    }

我收到此错误消息:

错误 1:无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”c:\users\furkan\documents\visual studio 2012\Projects\DvdKiralamaFurkanR\DvdKiralamaFurkanR\Service.cs

我在 SQL 上有 2 个普通表和 1 个桥接表。我想在 Linq 上连接它。但我没能成功。我怎样才能发回列表。

你能帮助我吗 ?

4

3 回答 3

2
public static List<Filmler> GetPlayerByMovie(int id)
    {
        var data = from o in db.Oyuncular
                   where o.OyuncularID == id
                   select new Filmler{populate properties here ex Id = o.Id};

        return data.ToList();
    }
于 2013-03-01T21:33:54.390 回答
0

You can just use the Enumerable.ToList() method in the linq for this

public static List<Filmler> GetPlayerByMovie(int id)
{
    var data = (from o in db.Oyuncular
                where o.OyuncularID == id
                select o).ToList();

    return data;
}
于 2013-03-02T10:49:20.463 回答
0

在您的列表中,您应该返回 Filmler 类型的对象的 lollection

 List<Filmler> GetPlayerByMovie(int id)

但你正试图返回一个 Oyuncular 类型的对象

 var data = from o in db.Oyuncular
                   where o.OyuncularID == id
                   select o;
  return data.ToList();

您可以返回类型 List<Oyuncular> GetPlayerByMovie(int id)

或将 Filmler 与 Oyuncular 匹配

  var data = (from o in db.Oyuncular
                       where o.OyuncularID == id
                       select  new Filmler {//Filmproperty=o.propperty};
于 2013-03-01T21:38:34.227 回答