in my MVC 3 project I’m usint the MySQL connector. When I try to invoke that method, I get the Specified method is not supported error. Why ?
public IList<Order> GetOrders()
{
return (from x in db.Order
where (x.Address.FirstOrDefault() != null)
orderby x.Created //it's a DateTime
descending select x).ToList();
}
edit
I see there’s a problem with the x.Address.FirstOrDefault() != null
edit2
That code also works
return (from x in db.Order
from y in db.Address
where (y.OrderID == x.OrderID)
orderby x.Created descending
select x).ToList();
With some ORM tools, not all of the LINQ methods are supported out of the box. I know I have had that exact message using NHibernate in the past. In order to achieve this you’ll have to rewrite your logic to use more traditional methods. Try this:
Or if for some reason you don’t like the above, your other alternative is to first bring the collection in memory by resolving it, then perform your logic (although bear in mind this will be slower as it’s bringing more data back from the database):