views:

19

answers:

1

I have a LINQ dbml class that I am wrapping in a POCO. I have built overloaded constructors that take the DBML class and init. the wrapper objects properties based on the dbml object passed in.

For example

public class MyPerson{

   public MyPerson(DBMLPerson p)
   {
        this.ID = p.ID;
        this.Name = p.Name;
   }
}

if I then do something like this where I return an IQueryable

{

return from p in datacontext.DBMLPerson
        select new MyPerson(p){};
}

When I try to do further queries on that Iquearble I get "System.NotSupportedException: The member 'MyPerson.ID' has no supported translation to SQL.."

However if I do this {

return from p in datacontext.DBMLPerson
        select new MyPerson(){
            ID = p.ID;
            Name = p.Name;
        };
}

I don't get an error at all and everything works perfect. Basically I want to have my class handle the conversion from LINQ object to POCO itself.

Basically I have to use the Object Initializer or I am unable to match on that field.

+1  A: 

Ok not sure this will actually help anyone but but myself but my whole problem is the I shouldn't be using IQuerable after a certain point(outside of my repository)

iqueryable-can-kill-your-dog-steal-your-wife-kill-your-will-to-live-etc

ctrlShiftBryan