目前我正试图在玩家死亡时用新的高分来更新我的数据库.但无论我选择尝试和保存,它都会向我抛出异常.
码:
Highscore hs = new Highscore(); var ID = from i in db.Highscores orderby i.ID descending select i; int newID = 0; if (ID.Count() == 0) { newID = 1; } else { newID = ID.First().ID + 1; } hs.ID = 6; //I just hardcoded in 6 to make sure i wasent because of the newID //thing,and i have checked if theres already something on the sixths spot as well. hs.UserHighscore = 100; hs.HighscoreUsername = "test"; hs.GameID = 1; db.Highscores.Addobject(hs); db.SaveChanges();
我一次又一次地检查过,我似乎无法弄清问题是什么.
任何帮助都会得到满足.
例外:
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.Map@[email protected](IEntityStateManager stateManager,IEntityAdapter adapter) at System.Data.EntityClIEnt.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Objects.ObjectContext.SaveChanges() at MatematikspilMenu.SaveBunnIEsSceen.SaveHighscore() in MatematikspilMenu\SaveBunnIEsSceen.cs:line 173 at MatematikspilMenu.SaveBunnIEsSceen.Update(GameTime gameTime,Boolean otherScreenIsActive,Boolean coveredByOtherScreens) in C:\Users\Etarnalazure-AlIEn\documents\visual studio 2010\Projects\MatematikspilMenu\MatematikspilMenu\MatematikspilMenu\SaveBunnIEsSceen.cs:line 110 at MatematikspilMenu.ScreenManager.Update(GameTime gameTime) in MatematikspilMenu\ScreenManager.cs:line 101 at Microsoft.Xna.Framework.Game.Update(GameTime gameTime) at Microsoft.Xna.Framework.Game.Tick() at Microsoft.Xna.Framework.Game.HostIDle(Object sender,EventArgs e) at Microsoft.Xna.Framework.GameHost.OnIDle() at Microsoft.Xna.Framework.windowsGameHost.RunOneFrame() at Microsoft.Xna.Framework.windowsGameHost.ApplicationIDle(Object sender,EventArgs e) at System.windows.Forms.Application.threadcontext.System.windows.Forms.UnsafeNativeMethods.imsoComponent.FDoIDle(Int32 grfIDlef) at System.windows.Forms.Application.ComponentManager.System.windows.Forms.UnsafeNativeMethods.imsoComponentManager.FPushMessageLoop(IntPtr DWComponentID,Int32 reason,Int32 pvLoopData) at System.windows.Forms.Application.threadcontext.RunMessageLoopInner(Int32 reason,ApplicationContext context) at System.windows.Forms.Application.threadcontext.RunMessageLoop(Int32 reason,ApplicationContext context) at System.windows.Forms.Application.Run(Form mainForm) at Microsoft.Xna.Framework.windowsGameHost.Run() at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun) at Microsoft.Xna.Framework.Game.Run() at MatematikspilMenu.Program.Main() in MatematikspilMenu\Game1.cs:line 120 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.Map@[email protected](DbModificationCommandTree commandTree) at System.Data.Map@[email protected](UpdateTranslator translator,Dictionary`2 IDentifIErValues) at System.Data.Map@[email protected](UpdateTranslator translator,EntityConnection connection,Dictionary`2 IDentifIErValues,List`1 generatedValues) at System.Data.Map@[email protected](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.GenerateReturningsql(StringBuilder commandText,DbModificationCommandTree tree,ExpressionTranslator translator,DbExpression returning) at System.Data.sqlServerCe.sqlGen.DmlsqlGenerator.GenerateInsertsql(DbInsertCommandTree tree,List`1& parameters,Boolean isLocalProvIDer) at System.Data.sqlServerCe.sqlGen.sqlGenerator.Generatesql(DbCommandTree tree,CommandType& commandType,Boolean isLocalProvIDer) at System.Data.sqlServerCe.sqlCeProvIDerServices.CreateCommand(DbProvIDerManifest provIDerManifest,DbCommandTree commandTree) at System.Data.sqlServerCe.sqlCeProvIDerServices.CreateDbCommandDeFinition(DbProvIDerManifest provIDerManifest,DbCommandTree commandTree) at System.Data.Common.DbProvIDerServices.CreateCommandDeFinition(DbCommandTree commandTree) at System.Data.Common.DbProvIDerServices.CreateCommand(DbCommandTree commandTree) at System.Data.Map@[email protected](DbModificationCommandTree commandTree) InnerException:解决方法 在我看来,问题的根源在于您使用的sql服务器:
Server-generated keys and server-generated values are not supported by
sql Server Compact.
您是否尝试在sql Server Compact版本上使用自动增量ID?我不记得了,但也许这个sql版本是不可能的.我建议你先检查一下.
总结以上是内存溢出为你收集整理的c# – 更新条目时发生错误.有关详细信息,请参阅内部异常 – Linq to Entity全部内容,希望文章能够帮你解决c# – 更新条目时发生错误.有关详细信息,请参阅内部异常 – Linq to Entity所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)