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
  • 66,413
  • 54
  • 311
  • 354
Hugo Pedrosa
  • 3
  • 1
  • 3

2 Answers2

6
IQueryable list = db.Object.Select(o => new Object(o))
tdragon
  • 3,129
  • 1
  • 15
  • 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,561
  • 6
  • 43
  • 73