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

后端 未结 5 1048
隐瞒了意图╮
隐瞒了意图╮ 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:28

    I guess Customer is a class you have defined yourself? The my suggestion would be to do something like the following:

    var results = db.Customers.Select(x => new Customer(x.Custname, x.CustEmail, x.CustAddress, x.CustContactNo)).ToList();
    

    The reason is that you are trying to return a list of Customer but the results from your link is an anonymous class containing those four values. This would of course require that you have a constructor that takes those four values.

提交回复
热议问题