1
votes

I had a column called ROWID in my DB and in the EF EDmX model. I did not want that column anymore so I dropped the column from the table (including the constraints and indexs it was using).

Then I deleted my entire EDMX model and recreated from the scratch. Now when I am updating an row inside this Table, it throws an exception saying

{"Invalid column name 'ROWID'.\r\nInvalid column name 'ROWID'."}

The error occurs when I use the dbContext.SaveChanges() method

Following is the stack trace:

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action'1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource'1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource'1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary'2 identifierValues, List`1 generatedValues) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

1
Are you sure the context and objects were recreated after you replaced the EDMX?Eris
Take a look at edmx, look for the entity, see if it has the ROWID property. If it does, delete the property.Fabio Luz
@Eris.. Yes, I have all classes from the db, present in the context file and the Context.tt files with updated Class definition (i.e, without the ROWID column) referenceMahesh
@FabioLuz.. I did check that as well. There is no reference of the Column name anywhere. I had tried once deleting manually and to be sure, I recreated model and rechecked for any reference.Mahesh
@Mahesh that's strange... how are you managing the dbcontext instance?Fabio Luz

1 Answers

1
votes

So I figured that the issue was due to a trigger present in the database. So EF does not actually save, but it triggers this save, where the ROWID column was still being referenced (Again this trigger and the column was created automatically by Entity Framework when migrating data from Oracle DB to SQL Server. And in this auto created trigger, the unique Identifier was set to default value instead of NEWID()).

So in case you are facing any similar issue, you should check if there are any triggers on the table you are modifying.