Cannot implicitly convert type '.List' to '.List'

后端 未结 5 1047
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 19:06

In the following code that returns a list:

public List GeAllCust()
{
    var results = db.Customers
        .Select(x => new { x.CustName,         


        
5条回答
  •  长发绾君心
    2020-12-28 19:20

    GetAllCust() is supposed to return a List of Customer, Select New will create a list of Anonymous Types, you need to return a list of Customer from your query. try:

    var results = db.Customers.Select( new Customer{CustName = x.CustName}).ToList(); //include other fields
    

提交回复
热议问题