Sujeet Raman

Sujeet Raman

  • 857
  • 927
  • 357.4k

How to convert List object in to model in .net core?

Jun 10 2021 5:00 PM

i have a model class

 public class Data
    {

         [JsonProperty("Id")]
        public string Id { get; set; }

   [JsonProperty("name")]
        public string name{ get; set; }

etc.........

}

 

i am getting a dataset using ado.net and i am getting to below method using  _DataAccessHelper. i am not allowed to change the method like  public List<Data>GetResults(string ServiceName)

    public async Task<Data>  GetResults(string ServiceName)
        {
            var result = _DataAccessHelper.GetdataResults(ServiceName);

            var DataList = result.Tables[0].AsEnumerable()
     .Select(dataRow => new RegressionData
     {
    
         Name = dataRow.Field<string>("Name")

                       etc......
}).ToList();

            return DataList ;   //cannot return because i cannot pass as a list

cannot give according to my project structure    public List<Data>  GetResults(string ServiceName)


        }
   

 

Can anyone help me...cs0029 cannot implicitly convert type list to model


Answers (1)