c# - Linq to SQL specflow, Cannot implicitly convert type 'System.Collections.Generic.List<' -


i'm using linq sql query in spec flow, , need pass results of query private field in binding class can access in later step files, try runs error

cannot implicitly convert type 'system.collections.generic.list<<anonymous type' 'system.collections.generic.list<string>'

the final query contain 15 - 20 variables. thoughts on how define private field in binding class?

public class member_dim_organizationssteps {      connectiondatacontext cmain = new connectiondatacontext();      static private list<string> mainstring;      [given(@"i have selected memberorganizations field values memberorganizations")]     public void givenihaveselectedthememberorganizationsfieldvaluesfrommemberorganizations()     {          var mainresults = (from mo in oecmain.memberorganizations                               orderby mo.orgid                               select new                               {                                   orgid = (mo.orgid),                                   orgkey = (mo.orgkey != null ? mo.orgkey : "").trim().toupper(),                                   baseorgkey = (mo.orgkey != null ? mo.orgkey.substring(0, 11) : "-----").toupper(),                                   manufacturerid = (convert.toint16(mo.manufacturerid != null ? mo.manufacturerid : 0)),                               });           mainstring = mainresults.tolist();       } 

if want keep results of query around, need define concrete type instead of using anonymous type:

public class result {     public int orgid {get; set;}     public string orgkey {get; set;}     public string baseorgkey {get; set;}     public int manufacturerid {get; set;} } 

use type list type"

private list<result> mainstring; 

then project type in query:

var mainresults = (from mo in oecmain.memberorganizations                    orderby mo.orgid                    select new result                    {                      orgid = (mo.orgid),                      orgkey = (mo.orgkey != null ? mo.orgkey : "").trim().toupper(),                      baseorgkey = (mo.orgkey != null ? mo.orgkey.substring(0, 11) : "-----").toupper(),                      manufacturerid = (convert.toint16(mo.manufacturerid != null ? mo.manufacturerid : 0)),                    });