问题描述
我需要在 linq 查询中调用构造函数.
我收到此错误:
<块引用>LINQ to Entities 仅支持无参数构造函数和初始化程序.
这是我的 linq 查询:
IQueryable<Object> list = (from u in db.Object select new Object(u));
这是我的构造函数:
public Object(Object presentation){}
推荐答案
你必须使用没有参数的构造器.
public Object() { public Object Presentation { get; set; } } IQueryable list= (from u in db.Object select new Object { Presentation = u });
问题描述
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){}
推荐答案
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 });