LINQ以下にはいくつかの方法があります。Convert.ToInt32
しかし、それは動作しません。インターネットを参照すると、変換の代わりにint.Parse
が使用されます。依然としてエラーが発生します。私にこれを行う方向を示してください。 Convert.ToInt32
を使用する場合LINQでIntに変換
:
コードLINQは、エラーをスロー上方ためのエンティティフレームワークを使用している:
クエリ以下でtody
のデータ型が更新DateTime
var ds = (from a in dbSetInvHeader
join b in dbSetCustomer on a.BusinessEntityID equals b.Id
join c in dbSetFinancialInfo on b.Id equals c.Id
where (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount) > 0
&& DbFunctions.AddDays(a.InvoiceDate, Convert.ToInt32(c.CreditPeriod)) >= tody
select new OverDueInvoices
{
CustomerName = b.Name,
InvoiceNo = a.InvoiceNo,
InvoiceAmount = a.TotalAmount - a.ApplyToInvoiceCreditAmount,
DueAmount = (a.TotalAmount - a.AppliedAmount - a.ApplyToInvoiceCreditAmount),
CreditAmount = a.ApplyToInvoiceCreditAmount,
NoOfDays = Convert.ToInt32(DbFunctions.DiffDays(tody, a.InvoiceDate))
}).ToList();
あります
"LINQ to Entitiesは、メソッド 'Int32 ToInt32(System.Decimal)'を認識せず、このメソッドをストア式に変換することはできません。
int.Parse
を使用して:「エンティティへのLINQのメソッド 『のInt32パース(可能System.String)』メソッドを認識しない、そしてこの方法は、ストア式に変換することができない」
を
に
null
を変換しようとしながら、あなたがInvalidCastException
を得ることができるよう(int)
にキャスト避ける方が良いでしょうNullable<int>
またはint?
を返しますか? –[EntityFunctions](https://msdn.microsoft.com/en-us/library/system.data.objects.entityfunctions(v = vs.110).aspx)を試してください。 –
"UPDATE 1"に詳細を追加しました – weeraa