Home

In constructors and initializers, only property or field parameter bindings are supported in LINQ

I am able to execute the below code snippet in my application and in linqpad.
Projects.Select(s => new ProjectName() { ProjectID = s.ProjectID, Name = s.Name })

Note that ProjectName is a parameterless constructor which exists in the following class:
namespace YeagerTechModel.DropDownLists { [DataContract] [Serializable] public partial class ProjectName { [DataMember] public Int16 ProjectID { get; set; } [DataMember] public String Name { get; set; } } }

However, the below code snippet works in my application, but not in linqpad. It gives the error on the subject line of this post. Can someone inform me how I should compose the query in linqpad?
Projects.Where(w => w.Status.Description == "Not Started").Select(s => new CustomerProjectDDL() { ProjectName = { ProjectID = s.Project, Name = s.Name }, Customer = { CustomerID = s.CustomerID, Email = s.Customer.Email, City = s.Customer.City, State = s.Customer.State, Zip = s.Customer.Zip } })

Note that CustomerProjectDDL is a parameterless constructor which contains two classes.
namespace YeagerTechModel.ViewModels { [DataContract] [Serializable] public partial class CustomerProjectDDL { [DataMember] public Customer Customer = new Customer(); [DataMember] public ProjectName ProjectName = new ProjectName(); } }

I need both of these classes in my View since it needs properties from both. Note that the Customer object was generated from a Code generation item on the ORM in Visual Studio using DbContext.
The ProjectName class is the first class I specified above in the post.

Note also that I am correctly referencing my dll and have the below namespace imports for the query:
YeagerTechModel YeagerTechModel.DropDownLists YeagerTechModel.ViewModels

Any help would be much appreciated...

Comments

Sign In or Register to comment.