Reputation: 671
i am trying to query data using linq, i am joining two tables where id == to id of the second table. i am getting an exception error saying
Cannot implicitly convert type '
System.Collections.Generic.List<AnonymousType#1>
' to 'System.Collections.Generic.List<--db table here-->
'.
var qry = context.Projects
.Join(context.Members, p => p.ID, m => m.ID, (p, m) => new { p, m })
.Where(u => u.m.ID == memId)
.Select(b => new {
b.p.ProjName,
b.p.ProjDesc,
b.p.ProjectType,
b.p.Tags
});
return qry.ToList();
Upvotes: 0
Views: 548
Reputation: 101681
You are trying to return a list of anonymous type from your method but the return type is probably something like List<SomeType>
.
So instead of creating anonymous objects you need to create objects of your type.
.Select(b => new SomeType {
// set properties here
});
Upvotes: 4