c# - How to return a LINQ Anonymoustype to a typed collection -
c# - How to return a LINQ Anonymoustype to a typed collection -
i having below linq want homecoming collectionlist.
var studids = _newids in newids.asenumerable() bring together _oldids in alloldids.asenumerable() on _newids.field<int>("id") equals _oldids.field<int>("id") _newids.field<boolean>("isexist") == true && _newids.field<string>("fieldname") == "finalvalue" select new { id = _newids.field<int>("id"), name = _newids.field<string>("name"), value = _newids.field<decimal>("price") }; list<std> lstcustomwebsiteverifiedindex = new list<std>();
this std class haivg id, name , value datamember.
any thought how typecast this?
instead of projecting anonymous class in first place should utilize std
class like:
select new std { id = _newids.field<int>("id"), name = _newids.field<string>("name"), value = _newids.field<decimal>("price") };
and later can do:
list<std> lstcustomwebsiteverifiedindex = studids.tolist();
but if class std
generated through framework (like entity framework) not able utilize projection, in case need temporary class.
also if can't modify existing code (with anonymous class) can utilize query project list like:
list<std> lstcustomwebsiteverifiedindex = studids.select(r=> new std { id = r.id, name = r.name, value = r.value, }) .tolist();
c# linq
Comments
Post a Comment