Exception: Only parameterless constructors and initializers are supported in LINQ to Entities.

I am not sure of the *exact* meaning and reason for this but I found something that can be good to know.  Or not.

return context.NuggetSet.Where(n => n.Name == name).Select(x => new MyClass(x)).ToList();

threw a

Only parameterless constructors and initializers are supported in LINQ to Entities.

When inserting a ToList it worked as suspected/wanted.

return context.NuggetSet.Where(n => n.Name == name).ToList().Select(x => new MyClass(x)).ToList();

My guess is that by calling ToList we losen EF’s grip of the entities and can do what we want with it.

Tags: , , ,

One Response to “Exception: Only parameterless constructors and initializers are supported in LINQ to Entities.”

  1. VP says:

    Hey, nice workaround! I wish we didn’t need it, but there you have it.

Leave a Reply to VP