执行以下代码时
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 工作室2012 \ Projects \ DvdKiralamaFurkanR \ DvdKiralamaFurkanR \ Service.cs
我在SQL上有2个普通表和1个桥表。我想在Linq上连接它。但我不能成功。我该如何发回List。
你能帮助我吗?
答案 0 :(得分: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();
}
答案 1 :(得分:0)
在你的列表中,你想要返回一个类型为Filmler的对象的选择
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)
或将电影制片人与Oyuncular匹配
var data = (from o in db.Oyuncular
where o.OyuncularID == id
select new Filmler {//Filmproperty=o.propperty};
答案 2 :(得分:0)
你可以在linq中使用Enumerable.ToList()方法来实现这个
public static List<Filmler> GetPlayerByMovie(int id)
{
var data = (from o in db.Oyuncular
where o.OyuncularID == id
select o).ToList();
return data;
}