2014-10-07 15 views
1

我想使用linq獲取稅碼,稅號和稅率列表。但它顯示了以下錯誤: 「DbExpressionBinding需要與集合與resultType輸入表達式 參數名:輸入」具有實體的Linq - DbExpressionBinding需要具有集合ResultType的輸入表達式。參數名稱:輸入

表數據

代碼|名稱|率

1 Tax1 4

1 Tax1.2 7

2 TAX2 5

3 Tax3 2

需要輸出

代碼|名稱|率

2 TAX2 5

3 Tax3 2

條件:檢索細節如果代碼的數量是一個。使用下面的查詢

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; 
+0

什麼是'txs.Code'? – DavidG 2014-10-07 10:06:41

+0

代碼是Ootax表中的字段。 – 2014-10-07 10:17:06

+0

那麼說'txs.Code.Count'是什麼意思? – DavidG 2014-10-07 10:17:32

回答

1

得到了解決:

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 };       

編碼愉快..

感謝, Indhu。

相關問題