This question is locked. New answers and comments are not allowed.
I have 2 classes
now I need to build query which will return me list of orders with their first image if it exists, I'm trying to run something like
but this doesn't worked. It throws exception
tried different ways to do this (for example o.Images.OrderBy(i=>i.DisplayOrder).FirstOrDefault()) - but it gave the same error.
Is there any way to accomplish my task by running one query on server? I guess I could use left join - but what will be best way performance wise?
Thanks!
class
Order
{
public
int
ID {
get
;
set
;}
public
IList<Image> Images {
get
;
set
;}
}
class
Image
{
public
int
ID {
get
;
set
;}
public
Order Order {
get
;
set
;}
public
int
DisplayOrder {
get
;
set
;}
}
now I need to build query which will return me list of orders with their first image if it exists, I'm trying to run something like
query.Select(o =>
new
{
ID=o.ID,
DefaultImage = o.Images.SingleOrDefault(i=>i.DisplayOrder==0)
});
but this doesn't worked. It throws exception
System.NotSupportedException : Execution of
'System.Linq.Enumerable:SingleOrDefault(IEnumerable`1,Func`2)'
on the database server side currently not implemented.
tried different ways to do this (for example o.Images.OrderBy(i=>i.DisplayOrder).FirstOrDefault()) - but it gave the same error.
Is there any way to accomplish my task by running one query on server? I guess I could use left join - but what will be best way performance wise?
Thanks!