私は外出するために頭を打ちたい私は以下、IEnumerable
にSystem.Collections.Generic.List
を変換することができないんだけどその中で、この問題の私のコードです:私は、アプリケーションを実行するとタイプ 'System.Collections.Generic.List`1のオブジェクトをキャストできません[<> f__AnonymousType6`65 [System.String、System.Decimal、System.Nullable`1
IEnumerable<PY_History_TransactionTAB> FilteredReport;
var ReportData = db.PY_History_TransactionTAB
.Where(x => x.SystemCode == SysCode)
.GroupBy(x => x.EmployeeCode);
FilteredReport = (IEnumerable<PY_History_TransactionTAB>)ReportData.Select(x => new
{
EmployeeCode = x.Key,
H_SalaryDays = x.Sum(y => y.H_SalaryDays ?? 0),
H_NET_Overtime = x.Sum(y => y.H_NET_Overtime),
H_Overtime_Amount = x.Sum(y => y.H_Overtime_Amount),
H_SL_Breakup1 = x.Sum(y => y.H_SL_Breakup1 ?? 0),
H_SL_Breakup2 = x.Sum(y => y.H_SL_Breakup2 ?? 0),
H_SL_Breakup3 = x.Sum(y => y.H_SL_Breakup3 ?? 0),
H_OT_Allowance1 = x.Sum(y => y.H_OT_Allowance1 ?? 0),
H_OT_Allowance2 = x.Sum(y => y.H_OT_Allowance2 ?? 0),
H_OT_Allowance3 = x.Sum(y => y.H_OT_Allowance3 ?? 0),
H_OT_Allowance4 = x.Sum(y => y.H_OT_Allowance4 ?? 0),
H_OT_Allowance5 = x.Sum(y => y.H_OT_Allowance5 ?? 0)
}).ToList();
、それはFilteredReport変数への代入の時点で、実行時例外System.InvalidCastException
をスローし、と言って:
{"Unable 'System.Collections.Generic.List'型のオブジェクトをキャストするには [System.String、System.Decimal、System.Nullable
1[System.Decimal],System.Nullable
1 [System.Decimal]、 System.Decimal、System.Decimal、System.Decimal、System .Decimal、System.Decimal、System.Decimal、System.Decimal、 System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal 、System.Decimal、System .Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、 System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimalシステム。 Decimal、 System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、 System.Decimal、System.Decimal、System.Decimal、System.Decimal、System .Decimal、System.Decimal、System.Decimal、 System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、 System.Decimal、System.Decimal、System .Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal、 System.Collections と入力するには、System.Decimal、System.Decimal、System.Decimal、System.Decimal、System.Decimal]] 'を使用します。 Generic.IEnumerable`1 [HrAndPayrollSystem.Models.PY_History_TransactionTAB]」。 "}
だから、私は何を取得することは、私は右つもりはないということです、私は私が得るために何をすべき、正しい方法を見つける必要がありますこの問題を解消するか、List
をIEnumerable
に変換する正しい方法は何ですか?どんなヘルプも深く感謝します、ありがとうございました!
更新:
[OK]を、ルネ・フォークトの答えは、上記の問題のために正しいですが、私は同じポイント格言で別の例外System.NotSupportedException
が発生します。
エンティティまたは複合型 'HrAndPayrollSystem.Models.PY_History_TransactionTAB' は、LINQ to Entitiesクエリでは構築できません。
どうすれば解決できますか?
ご回答いただきありがとうございます。だから、これは非常に正しく聞こえる、今私は別の例外が発生しました、私の更新された質問を参照してください。 –
@BilalAhmed、この回答があなたの問題を解決した場合、それは受け入れられるべきです。別の問題がある場合は、別の質問をしてください –
@StephenMuecke私の悪い! –