c# - Entity Framework 7 Beta5 - DbUpdateException resolution -


i having issues using entity framework simple crud operations. believe configured correctly, when call savechanges after adding entity dbset, dbupdateexception thrown. i'm not quite sure code provide, i'm going include exception detail , logic involved.

exception detail:

microsoft.data.entity.update.dbupdateexception occurred   hresult=-2146233088   message=an error occurred while updating entries. see inner exception details.   source=entityframework.relational   stacktrace:        @ microsoft.data.entity.relational.update.readermodificationcommandbatch.execute(relationaltransaction transaction, irelationaltypemapper typemapper, dbcontext context, ilogger logger)        @ microsoft.data.entity.relational.update.batchexecutor.execute(ienumerable`1 commandbatches, irelationalconnection connection)        @ microsoft.data.entity.relational.relationaldatastore.savechanges(ireadonlylist`1 entries)        @ microsoft.data.entity.changetracking.internal.statemanager.savechanges(ireadonlylist`1 entriestosave)        @ microsoft.data.entity.changetracking.internal.statemanager.savechanges(boolean acceptallchangesonsuccess)        @ microsoft.data.entity.dbcontext.savechanges(boolean acceptallchangesonsuccess)        @ microsoft.data.entity.dbcontext.savechanges()        @ uniti.data.repository`1.add(t entity) in d:\alex\projects\uniti\src\uniti.data\repository.cs:line 38   innerexception:         class=16        errorcode=-2146232060        hresult=-2146232060        linenumber=2        message=invalid object name 'unitipost'.        number=208        procedure=""        server=(localdb)\mssqllocaldb        source=.net sqlclient data provider        state=1        stacktrace:             @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)             @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)             @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose)             @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready)             @ system.data.sqlclient.sqldatareader.tryconsumemetadata()             @ system.data.sqlclient.sqldatareader.get_metadata()             @ system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring)             @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite, sqldatareader ds, boolean describeparameterencryptionrequest)             @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite)             @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method)             @ system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method)             @ system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior)             @ system.data.common.dbcommand.executereader()             @ microsoft.data.entity.relational.update.readermodificationcommandbatch.execute(relationaltransaction transaction, irelationaltypemapper typemapper, dbcontext context, ilogger logger)        innerexception:  

repository add method

public bool add(t entity)     {         _context.add(entity);          _context.entry(entity).state = entitystate.added;         return _context.savechanges() > 0;     } 

controller action add unitipost

[httppost]     [route("add")]     [authorize("bearer")]     public async task<iactionresult> add([frombody] unitipostadddto postaddmodel)     {         if (modelstate.isvalid)         {             var user = await usermanager.findbyidasync(user.getuserid());              var post = new unitipost             {                 creator = user,                 createdatetime = datetime.utcnow,                 updatedatetime = datetime.utcnow,                 content = postaddmodel.content             };              var add = repository.add(post);             if (!add)             {                 return json(false);             }              return json(true);         }          return json(new failureresult(null, modelstate));     } 

if need more information solve issue, able give individual access github repo, private repo, cannot open everyone.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -