ورود

View Full Version : سوال: خطای entity framework هنگام درج در جداولی که فیلد Auto increment یا همون identity دارند.



ShahinRad97
شنبه 26 دی 1394, 23:12 عصر
سلام
من با ویژوال استدیو 2010 برنامه ای نوشتم.
مشکل اینه که در جداولی که فیلد identity ندارن بدون هیچ مشکلی رکورد اضافه میشه ولی در جداولی که فیلد مثلا id به صورت identity تعریف شده هنگام درج رکورد به وسیله ef/linq خطا میده.

نمونه ساده شده برنامه رو پیوست کردم:
138439

Mahmoud.Afrad
یک شنبه 27 دی 1394, 16:50 عصر
شما نباید به ستونی که identity اون true هست مقدار بدید.

ShahinRad97
یک شنبه 27 دی 1394, 17:43 عصر
شما نباید به ستونی که identity اون true هست مقدار بدید.

مقدار ندادم

Mahmoud.Afrad
دوشنبه 28 دی 1394, 01:28 صبح
متن خطا چیه؟

ShahinRad97
دوشنبه 28 دی 1394, 20:16 عصر
An error occurred while updating the entries. See the inner exception for details.

bomb23
شنبه 03 بهمن 1394, 15:09 عصر
سام خب inner exeption رو باز کنید خطای اونو اعلام کنید!

ShahinRad97
دوشنبه 05 بهمن 1394, 22:51 عصر
System.Data.UpdateException was unhandled
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslat or.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEnt ityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(Save Options options)
at System.Data.Objects.ObjectContext.SaveChanges()
at WindowsFormsApplication2.Form1.button2_Click(Objec t sender, EventArgs e) in C:\Documents and Settings\Administrator\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsForm sApplication2\Form1.cs:line 38
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication2.Program.Main() in c:\documents and settings\administrator\my documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsForm sApplication2\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.EntityCommandCompilationException
Message=An error occurred while preparing the command definition. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslat or.CreateCommand(DbModificationCommandTree commandTree)
at System.Data.Mapping.Update.Internal.DynamicUpdateC ommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
at System.Data.Mapping.Update.Internal.DynamicUpdateC ommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslat or.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
InnerException: System.NotSupportedException
Message=Server-generated keys and server-generated values are not supported by SQL Server Compact.
Source=System.Data.SqlServerCe.Entity
StackTrace:
at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.Gen erateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, ExpressionTranslator translator, DbExpression returning)
at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.Gen erateInsertSql(DbInsertCommandTree tree, List`1& parameters, Boolean isLocalProvider)
at System.Data.SqlServerCe.SqlGen.SqlGenerator.Genera teSql(DbCommandTree tree, List`1& parameters, CommandType& commandType, Boolean isLocalProvider)
at System.Data.SqlServerCe.SqlCeProviderServices.Crea teCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.SqlServerCe.SqlCeProviderServices.Crea teDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateComman dDefinition(DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateComman d(DbCommandTree commandTree)
at System.Data.Mapping.Update.Internal.UpdateTranslat or.CreateCommand(DbModificationCommandTree commandTree)
InnerException:

Felony
پنج شنبه 08 بهمن 1394, 06:36 صبح
Message=Server-generated keys and server-generated values are not supported by SQL Server Compact.

نوع داده ای که داری به بانکت پاس میدی باهاش ( SQL Compace ) سازگاری نداره - کد entity مربوطه رو بزار .