Reputation: 21
I am trying to get the taxcode, taxname and taxrate as list using linq. But it's showing the following error: "DbExpressionBinding requires an input expression with a collection ResultType. Parameter name: input"
Table Data
Code | Name | Rate
1 Tax1 4
1 Tax1.2 7
2 Tax2 5
3 Tax3 2
Need Output
Code | Name | Rate
2 Tax2 5
3 Tax3 2
Condition : Retrieve the details if the number of code is one.
UAAPPEntities context;
context=new UAAPPEntities();
var x = from txs in context.OTAXs
where txs.Code.Count()<=1
select new TaxModel{ taxCode=txs.Code, taxName=txs.Name,taxRate=txs.Rate.Value };
taxList = x.ToList();
return taxList;
Upvotes: 1
Views: 2360
Reputation: 21
Got solution using the following query:
var x = from t1 in context.OTAXs
group t1.Code by new { t1.Code } into g
where g.Count()<=1
join txs in context.OTAXs on g.Key.Code equals txs.Code
select new TaxModel { taxCode = txs.Code, taxName = txs.Code, description = txs.Code, taxRate = txs.Rate.Value };
Happy coding..
Thanks, Indhu.
Upvotes: 1