c# - LINQ - Cannot implicitly convert type with custom data model list property -


despite dozens of browser tabs open various linq threads, still cannot seem particular linq query work correctly.

i'm working in asp.net mvc 5 web application , exact error message is:

cannot implicitly convert type  'system.collections.generic.list<string>'  'system.collections.generic.list<turboapp.models.submodel>' 

in controller, i'm trying build custom data model can hand off view. curve ball need group data in such way can have list of part/engine details, multiple "submodels" of vehicle part fit. query looks this:

var parts = _db.vwfullpartdata .where(d => d.vehiclemakeid == make &&     d.vehiclemodelid == model &&     d.vehicleyearid == year) .take(20) .groupby(d => new { d.pn, d.description, d.cyl, d.liter, d.fuel }) .select(x => new turbodetailslistviewmodel {     pn = x.key.pn,     description = x.key.description,     cyl = x.key.cyl,     liter = x.key.liter,     fuel = x.key.fuel,      submodels = x.select(s => s.submodel).tolist() }); 

then pass parts view:

return partialview("_partlist", parts); 

it's entirely possible have missed simple in model. i'm focused on submodel column in table , need build sort of set of applicable submodels. i'm trying use list let me know if there's better way. here's model, called turbodetailslistviewmodel.cs

namespace turboapp.models {     public class turbodetailslistviewmodel     {         public string pn { get; set; }         public string description { get; set; }         public string cyl { get; set; }         public decimal? liter { get; set; }         public string fuel { get; set; }         public list<submodel> submodels { get; set; }     }      public class submodel     {         public string submodelname { get; set; }     } } 

maybe 1 of pros out there can point me in right direction! think ok building view once have model filled in correctly. i'm planning on using nested razor foreach loops.

thanks time!

try this:

submodels = x.select(s => new submodel{submodelname = s.submodel}).tolist() 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -