"orphaned" properties after datasource changes

Hello there,

I created a CRUD page "person" from underlying table "person". Now, I`ve made changes to the data source in Radzen: I deselected some columns (including some foreign-key-columns) from the underlying table because they will be used no more in my application.

But when I try to add or edit data, there is always an error:

dotnet: fail: Microsoft.EntityFrameworkCore.Update[10000]
An exception occurred in the database while saving changes for context type 'GslpaMdev.Data.GslpamDbContext'.
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Codetab_ID'.
Invalid column name 'Codetab_ID1'.
Invalid column name 'Codetab_ID2'.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
ClientConnectionId:56c2d2ff-5071-479a-85b4-da41deccb0cc
Error Number:207,State:1,Class:16
--- End of inner exception stack trace ---

The described invalid column names "Codetab_ID1", "Codetab_ID2", "Codetab_ID3" have been referenced by the deselected foreign key columns before. The problem does not appear on the other deselected columns, only the foreign key columns are affected.

It seems to me that they are not properly removed from the renderer. Even when I global-search my project in VSCode, I cannot find them.

Is there a way to force a "refresh" of all (odata-)dependencies in my application?

Thanks in advance,

Martin

Hi @mkfromhighlands,

You can recreate the auto-generated pages. When you just remove a database field Radzen will not update any of the pages that are generated initially. Be careful when regenerating pages - you might loose some custom code.

Hi,

thanks for the quick answer.

Again, to clarify: the problem only occurs on foreign key columns.
Simply re-create the CRUD-Pages is not really an option for me because I would lost a lot of custom code and configuration. Any other suggestions, maybe?

Thanks in advance,

Martin

In this case you need to manually remove/rework all DataGrid columns on all pages where there is FK with these properties.

Columns have been removed everywhere. It seems that radzen`s create and update procedures still use an "old" version of the datamodel...

This is what create procedure logs, but there are no relations anymore:

dotnet: warn: Microsoft.EntityFrameworkCore.Model[10605]
There are multiple relationships between 'Person' and 'Codetab' without configured foreign key properties causing EF to create shadow properties on 'Person' with names dependent on the discovery order.

This is what create procedure tries to do, but there are no columns (bold) matching the insert statement:

dotnet: fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (4ms) [Parameters=[@p0='?' ..., CommandType='Text', CommandTimeout='30']
SET NOCOUNT ON;
INSERT INTO [schema].[table] (..., [Codetab_ID], [Codetab_ID1], [Codetab_ID2], ...)
VALUES (@p0, ...);
SELECT [...;

I'm afraid that I've never seen such problem before. Check the DbContext what relations are declared- for example:

I checked DbContext.cs. The removed columns are no longer included there.
Maybe it is better/faster to rebuild the pages.

@enchev, @korchev Could you please analyze the problem anyway? I don't want to believe that removing relational columns from datasource requires the complete CRUD page to be rebuilt every time.

Thanks in advance,

Martin

Hi,

Please send us your application to info@radzen.com along with your database schema.

@enchev,@korchev

just for info: the problem also occurs when you add a relation column to the database without adding this column to the data model in radzen

keep up the good work!

martin

This is how EF will behave if the database is not fully described. There is not much we can do.