I want to achieve the following:
return (from a in db.Tags
select new TagItem
{
ID = a.Id,
Name = a.Name
});
..but i don't want to achieve it like that, because i need to use the exact same TagItem construction elsewhere (for a join)
So this is the intention, to call a method that constructs the TagItem for me:
return (from a in db.Tags
select ConstructTagItem(a));
And the method constructs the object the same way:
private TagItem ConstructTagItem(Tag a)
{
return new TagItem { ID = a.Id, Name = a.Name};
}
But this gives me the following error:
Method 'TagItem ConstructTagItem(Tag)' has no supported translation to SQL.
Is there any way to achieve this ?
Solution (thanks Daniel Hilgarth):
return db.Tags.Select(ConstructTagItem);
And the method:
private Expression<Func<Tag, TagItem>> ConstructTagItem
{
get { return a => new TagItem {ID = a.Id Name = a.Name }; }
}