Reputation: 21
When calling _tld.SaveChanges();
I get this error:
SqlException: Changing a datetime bus of the datetime2 data type resulted in an out-of-range value. The statement was terminated.
My project uses Entity Framework database-first and a SQL Server. What is this the solution for this problem?
This is my code in which I get this exception:
public static Result SavePendingTransactionsData(transaction[] model)
{
Authorize authorize = new Authorize();
using (TechLogisticsEntities _tld = new TechLogisticsEntities())
{
try
{
foreach (var item in model)
{
L_ROD_AsTwentyFourTransaction asTwentyFourTransaction = new L_ROD_AsTwentyFourTransaction();
asTwentyFourTransaction.TransactionNumber = item.transactionNumber;
asTwentyFourTransaction.TransactionType = item.transactionType;
asTwentyFourTransaction.TransactionDate = item.entryTransactionDate;
asTwentyFourTransaction.VehiclePlate = item.VCRegistrationNumber;
asTwentyFourTransaction.VehicleId = int.Parse(item.VCNumber);
//asTwentyFourTransaction.TransactionAmount =
//asTwentyFourTransaction.CurrencyId =
//asTwentyFourTransaction.CurrencyCode =
//asTwentyFourTransaction.GrossAmount =
//asTwentyFourTransaction.TransactionValue =
//asTwentyFourTransaction.Unit =
//asTwentyFourTransaction.TransactionCountryName =
//asTwentyFourTransaction.TransactionCountryCode =
//asTwentyFourTransaction.TransactionLocation =
//asTwentyFourTransaction.ObuId =
//2 olan
asTwentyFourTransaction.StatusId = 1;
//asTwentyFourTransaction.StatusCode =
_tld.L_ROD_AsTwentyFourTransaction.Add(asTwentyFourTransaction);
_tld.SaveChanges();
}
return new Result() { IsSuccess = true };
}
catch (Exception ex)
{
return new Result() { IsSuccess = false, UserMessage = ex.Message };
}
}
}
Upvotes: 1
Views: 43