wpf - Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.List -
i newbie in .net world, trying achieve result linq. please help.
following error getting.
error 4 cannot implicitly convert type 'system.linq.iqueryable' 'system.collections.generic.list'. explicit conversion exists (are missing cast?) ..business\dal\globalrequest.cs 39 27 business
public observablecollection<accountsummary> getaccountsummary() { observablecollection<accountsummary> list; list = listdata in (from in dbc.accounts join b in dbc.ledgers on a.account_id equals b.account_id t2 t2data in t2.defaultifempty() a.is_mannual == convert.tochar("y") select new { account_id = a.account_id, account_name = a.account_name, amount = t2data.amount == null ? 0 : t2data.amount } ).orderby(item => item.account_name) group listdata new { listdata.account_id, listdata.account_name } groupdata select new { account_id = groupdata.key.account_id, account_name = groupdata.key.account_name, amount = groupdata.sum(ol => ol.amount) }; } class accountsummary { public decimal accountid { get; set; } public string accountname { get; set; } public decimal amount { get; set; } }
please advice.
your query projecting collection (sequence) of anonymous types:
select new { account_id = groupdata.key.account_id, account_name = groupdata.key.account_name, amount = groupdata.sum(ol => ol.amount) };
you need project collection of accountsummary
, e.g:
var accountsummaries = ...rest of query here select new accountsummary { accountid = ..., accountname = ..., etc. };
you can create observable collection collection of accountsummary
:
list = new observablecollection(accountsummaries);
Comments
Post a Comment