Разбираюсь потихоньку с Entity. На этот раз проблема в добавлении записи в таблицу Mysql. Таблица :
CREATE TABLE `cashaccounts` (
`orderKlient` varchar(45) NOT NULL,
`CA_USD` decimal(10,2) NOT NULL,
`CA_EUR` decimal(10,2) NOT NULL,
`CA_GBP` decimal(10,2) NOT NULL,
`CA_SGD` decimal(10,2) NOT NULL,
`CA_AUD` decimal(10,2) NOT NULL,
`CashAllocation` decimal(10,2) NOT NULL,
`DATEH` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Сущность в edmx (подход DataBaseFirst) :
public partial class cashaccounts
{
public string orderKlient { get; set; }
public decimal CA_USD { get; set; }
public decimal CA_EUR { get; set; }
public decimal CA_GBP { get; set; }
public decimal CA_SGD { get; set; }
public decimal CA_AUD { get; set; }
public decimal CashAllocation { get; set; }
public System.DateTime DATEH { get; set; }
}
И сам код, добавляющий новую строку в таблицу :
public void NewCashHistory()
{
var newRow = new cashaccounts();
newRow.orderKlient = order;
newRow.CashAllocation = cashallocation;
newRow.CA_AUD = 11.22M;
newRow.CA_EUR = 11.22M;
newRow.CA_GBP = 11.22M;
newRow.CA_SGD = 11.22M;
newRow.CA_USD = 11.22M;
newRow.DATEH = DateTime.Now;
using (custodianhistoryEntities1 Context = new custodianhistoryEntities1())
{
Context.cashaccounts.Add(newRow);
Context.SaveChanges(); // тут ошибка
};
}
При попытке сохранить изменения вылетает ошибка :
Необработанное исключение типа "System.Data.Entity.Infrastructure.DbUpdateException" в EntityFramework.dll
Дополнительные сведения: При обновлении записей возникла ошибка. Дополнительные сведения приведены во внутреннем исключении.
Подозреваю что дело в формате даты, так ил это? Кто сталкивался, подскажите как исправить?
Больше сведений об исключении :
StackTrace: в System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() в System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator ut) в System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func
2 updateFunction) в System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() в System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() в System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func
1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) в System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) в System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.b__27() в System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func1 operation) в System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) в System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) в System.Data.Entity.Internal.InternalContext.SaveChanges() InnerException: ErrorCode=-2147467259 HResult=-2147467259 Message=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT
cashaccounts.
orderKlient,
cashaccounts.
CA_USD,
cashaccounts`.' at line 1 Number=1064 Source=MySql.Data