Я получаю следующую ошибку при попытке получить сумму в этом запросе Linq :
InvalidCastException не обработано.Указанное приведение недопустимо.
Я использовал свойство DataType для тройной проверки, является ли столбец фактически двойным, и это так.
foreach (DataColumn item in _dttMasterViewTransaction.Columns)
{
if (item.ColumnName == "Dr")
{
//Outputs: System.Double!
MessageBox.Show(item.DataType.ToString());
}
}
var datos = _dttMasterViewTransaction.AsEnumerable().Where(r => (int)r["Entity"] == FundsID).Select(r => new EntityJESummary()
{
JEId = (int)r["JE ID"],
JEGroupingId = (int)r["JE Group"],
PartnershipId = (int)r["Entity"],
BookingDate = Convert.ToDateTime(r["GL Date"]),
EffectiveDate = Convert.ToDateTime(r["Effective Date"]),
Allocated = Convert.ToBoolean(r["Allocated"]),
JEEstate = (int)r["JE State"],
JEComments = r["JE Comments"].ToString(),
Debit = _dttMasterViewTransaction.AsEnumerable().Where(s => (int)r["Entity"] == FundsID).Sum(s => (double)s["Dr"]),
Credit = _dttMasterViewTransaction.AsEnumerable().Where(s => (int)r["Entity"] == FundsID).Sum(s => (double)s["CR"])
}).First();
Любые предложения о том, почему это может произойти?