Reputation: 23
I want to return a list with entity framework
using (FinalDatabaseEntities fdb = new FinalDatabaseEntities())
{
var result = from Port in fdb.Ports select Port.Name;
result = result.ToList();
}
I wish to return a list or array (list preferably) and place it in my result
variable
I'm getting the following error
Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?) Finally!! C:\Users\Kudzai Mhlanga\source\repos\Finally!!\Program.cs 22 Active
Upvotes: 0
Views: 241
Reputation: 89006
You just need a second local variable, which also makes your code more readable, since the first line creates a "query" not a "result". So:
using (FinalDatabaseEntities fdb = new FinalDatabaseEntities())
{
var query = from Port in fdb.Ports select Port.Name;
var result = query.ToList();
}
Upvotes: 2
Reputation: 1
Your Code will be :
using (FinalDatabaseEntities fdb = new FinalDatabaseEntities())
{
var result = (from port in fdb.Ports select port.Name).ToList();
}
Upvotes: 0