とコンストラクタは、私はクラスの従業員を作成します。コードまずEntity Frameworkの、選択ViewModelに - パラメータ
public class Employees : BaseModel
{
[Key]
public int EmployeeId { get; set; }
// [ohter parameter]
public int? DepartmentId { get; set; }
public virtual Departments Departments { get; set; }
public int? OccupationId { get; set; }
public virtual Occupations Occupations { get; set; }
}
私はビューモデルを作成したいです。
public class Employee_ViewModel
{
public Employee_ViewModel(Employees item)
{
this.EmployeeId = item.EmployeeId;
//[other parameter]
this.DepartmentId = item.DepartmentId;
this.OccupationId = item.OccupationId;
}
public int EmployeeId { get; set; }
//[other parameter]
public string DepartmentName { get; set; }
public string OccupationName { get; set; }
}
ように見えるEmployee_ViewModel返す私の方法:最後に、私はエラーを取得する
List<Employee_ViewModel> item = contex.Employees.Where(w => w.IsActive == true && w.IsVisible == true)
.Include(i => i.Departments)
.Include(i => i.Occupations)
.Select(s => new Employee_ViewModel(s)
{
OccupationName = s.Occupations.Name,
DepartmentName = s.Departments.Name
})
.ToList();
:
Only parameterless constructors and initializers are supported in LINQ to Entities.
ソリューションは、このポストを形成する:
Only parameterless constructors and initializers are supported in LINQ to Entities
は動作していますが、なぜ私のコンストラクタは動作しませんか?
例外メッセージ(**パラメータなし**)からは明らかではありません。これは何度も繰り返し尋ねられています。 –
私は知っているが、私はパラメータを簡単に書き直したい。 – 18666