Arun D
Arun D

Reputation: 279

Cannot implicitly convert type 'System.Collections.Generic.List<>' to ''

I have written code as below for return list using class as below

 public class UsersModel
    {
        public List<CaseValues> CaseDetails { get; set; }
        public CaseValues GetCasedetails(string userName)
        {
            using (var cases = new RassiEntities())
            {
                CaseDetails = (from list in cases.Accidents
                               join users in cases.aspnet_Users on list.LockedBy equals users.UserId
                               select new CaseValues
                               {
                                   CaseId = list.caseid
                               }).ToList();
            }
            return CaseDetails ;
        }
    }

    public class CaseValues
    {
        public int CaseId { get; set; }
    }

Please share your suggestion.

Upvotes: 0

Views: 1652

Answers (2)

Gulam Husain Ansari
Gulam Husain Ansari

Reputation: 165

Change the return type.

public List<CaseValues> GetCasedetails(string userName)

or change the return value to single object of CaseValues like below code

return CaseDetails.FirstOrDefault();

Hope this will help

Upvotes: 2

Sajeetharan
Sajeetharan

Reputation: 222522

Your method returns List<CaseValues>, so the signature should be,

 public List<CaseValues>  GetCasedetails(string userName)

Upvotes: 2

Related Questions