0

I need to invoke a constructor inside of a linq query.

I am getting this error:

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

Here's my linq query:

IQueryable<Object> list = (from u in db.Object select new Object(u));

Here is my constructor:

public Object(Object presentation){}
nawfal
  • 70,104
  • 56
  • 326
  • 368
Hugo Pedrosa
  • 3
  • 1
  • 3

2 Answers2

6
IQueryable list = db.Object.Select(o => new Object(o))
tdragon
  • 3,209
  • 1
  • 16
  • 17
3

You have to use a contructor without parameters.

public Object()
{
    public Object Presentation { get; set; }
}

IQueryable list= (from u in db.Object select new Object { Presentation = u });
albertjan
  • 7,739
  • 6
  • 44
  • 74