views:

279

answers:

1

I have the below call in my repository where I return IQueryable of Node (my business object class) then I have a filter function in my service layer which adds to the IQueryable call and filters the repository function GetNodes by id. When I return the FilterById as a list (so it executes) I get error -- The member 'bo.Node.Id' has no supported translation to SQL. --

Is there a way to get around this error when returning a not linq generated class as IQueryable?

public IQueryable<bo.Node> GetNodes()
{
       return (from item in Db.Nodes select new bo.Node(item.id, 
              item.created, item.lastupdated, item.name, 
              item.parentid, item.siteid, item.userid));
}

In my service layer

private IQueryable<bo.Node> FilterById(IQueryable<bo.Node> source, Guid id)
{
       return source.Where(i => i.Id.Equals(id))
}
+1  A: 

Don't use Node constructor, instead use property initialization:

return (
   from item in Db.Nodes select new bo.Node{
      item.id, item.created, item.lastupdated, item.name, 
      item.parentid, item.siteid, item.userid
   });

afaik by using the constructor you don't give any info in the expression of what properties match others. Besides the resulting instance is based on whatever logic is in the constructor, so there is no any valid assumption linq can make about those ... other than just call the constructor when returning the instance of it.

eglasius
perfect, can't believe its so simple
monkeylee