I’m using linq-to-EF and I have this:
public IQeuryable<base01> GetData()
{
var u = this.ObjectContext.base01;
IQueryable<base01> u2 = u.OrderBy(o => o.article)
.Select(l => new { Id = l.Id, article = l.article, lot = l.lot}) as IQueryable<base01>;
return u2;
}
Basically, u contains the result of a query and I’m looking to sort and rearrange the columns. When I replace return u2 with return u I get what the result set filled but whe I go for return u2 I get a null.
What’s the problem that I’m not seeing?
Thanks.
The problem is
as– you are projecting to an anonymous type in your query not tobase01– soaswill returnnull. Instead create new instances ofbase01in your projection and remove theasoperator:Edit:
If
uis already anIQueryable<base01>andbase01is one of your entities you do not need theSelect()projection at all since you already have the type you want: