i want to be able to do such a projection:
var result = from record in MyTable
select MapTo( record );
/*
select new RecordModel( )
{
RecordId = record.Id,
Property1 = record.Property1
};
*/
private RecordModel MapTo( MyTable dbRecord )
{
return new RecordModel( )
{
RecordId = dbRecord.Id,
Property1 = dbRecord.Property1
};
}
but i always get a ‘NotSupportedException’ (has no supported translation to sql).
I’m not sure if this is even possible but it would be nice^^
Maybe this is possible when i use an expression but i don’t know how to code such an expression.
Linq tries to add the method to the query and sees it cannot be translated to Sql.
To be able to execute any CLR method in the Linq query, you need to execute the sql part of it first, so that you operate on in-memory objects. Like this:
Anything that forces MyTable to enumerate its entries should work.