asp.net mvc - Only parameterless constructors and initializers are supported in LINQ to Entities? -
i have productviewmodel converts dto (product) @ runtime.
public class productviewmodel : iviewmodel { public productviewmodel() { categories = new list<categoryviewmodel>(); } #region dto helpers public productviewmodel(product p) { this.id = p.id; this.name = p.name; this.price = p.price; categories = new list<categoryviewmodel>(); } #endregion public int id { get; set; } public string name { get; set; } public decimal price { get; set; } public ienumerable<categoryviewmodel> categories { get; set; } }
i've used code linq2sql before , it's worked, entity framework doesn't:
var products = (from p in db.getall() select new productviewmodel(p));
i error:
only parameterless constructors , initializers supported in linq entities
can explain/fix this?
var products = (from p in db.getall() select new productviewmodel{ id = p.id, .... });
Comments
Post a Comment