How to convert LINQ query result to list and return generic List? -
i used generic orm list example.
this table.
person table guid name lastname
and struct class.
public struct personitem // database , class field names same { public guid guid{ get; set; } public string name { get; set; } public string lastname { get; set; } } public struct personitems { public personitems() { items = new list<personitem>(); } public list<personitem> items { get; set; } }
i'm using such , no problem have write field's
public personitems getpersons() { var query = (from p in _dbentities.t_crew select p).tolist(); if (query != null) { foreach (var item in query) { _personitems.items.add(new personitem { guid = item.guid, name = item.name, lastname = item.lastname }); } } return _personitems; } public personitems getpersons() { personitems personitems = new personitems(); var query = p in _dbentities.t_person select p; >> here query need convert linq query result list personitems = query.tolist(); return personitems ; } error
cannot implicitly convert type system.collections.generic.list' persondata.personitems'.
try this
public personitems getpersons() { personitems personitems = new personitems(); var query = (from p in _dbentities.t_person select new personitems { test = p.somename, //other stuff //... }).tolist(); return query; }
Comments
Post a Comment