Reputation: 31
When executing the following code
public static List<Filmler> GetPlayerByMovie(int id)
{
var data = from o in db.Oyuncular
where o.OyuncularID == id
select o;
return data.ToList();
}
I get this error message:
Error 1: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' c:\users\furkan\documents\visual studio 2012\Projects\DvdKiralamaFurkanR\DvdKiralamaFurkanR\Service.cs
I have 2 normal tables, and 1 bridge table on SQL. and i want to connect this on Linq. But I couldn't succeed. How can I post back List.
Can you help me ?
Upvotes: 0
Views: 109
Reputation: 1640
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;
}
Upvotes: 0
Reputation: 13579
in you list you supose to return a lollection of object of type Filmler
List<Filmler> GetPlayerByMovie(int id)
but you are trying to return an object of type Oyuncular
var data = from o in db.Oyuncular
where o.OyuncularID == id
select o;
return data.ToList();
you can either return the type List<Oyuncular> GetPlayerByMovie(int id)
or match Filmler with Oyuncular
var data = (from o in db.Oyuncular
where o.OyuncularID == id
select new Filmler {//Filmproperty=o.propperty};
Upvotes: 0
Reputation: 13399
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();
}
Upvotes: 2