我想在Linq查询中创建一些类的对象,但给我一个错误,这个问题。实现IEnumerable'System.Collections.Generic.List`1'的类型不能在LINQ to Entities查询中初始化
我的查询是:
List<oneViewModel> workOrderInfoList = (from abc in db.ABC
join customer in db.Customers on abc.CustomerId equals customer.CustomerId into customers
select new oneViewModel()
{
CustomerId = abc.CustomerId,
OrderNumber = workOrderInfo.OrderNumber,
OrderDate = abc.OrderDate,
SecondClassList = new List<SecondClass>(),
}).ToList();
我在AS内部oneViewModel对象定义类的列表。
public class ABC
{
public DateTime? WorkOrderDate { get; set; }
public long CustomerId { get; set; }
public string CustomerName { get; set; }
public List<SecondClass> SecondClassList { get; set; }
}
我怎样才能在一个一举两得?我已经在ABC内部公布了第二个班级名单。 –
查看更新答案。 –
感谢Ryan的回应,但我不知道我该如何声明并用它在构造函数中进行设置。我已经接受了帕维尔的回答。 –