There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
During DbDatabaseExist call, the AssociationSet do not have correct details; if Fluent APIs or Data Annotations are used to modify the Table Name participating in the ForeignKey relationship. The AssociationSet still preserves the old name defined in the
We are third party EF provider and we are seeing an issue with CreateIfNotExist. With this call our provider generates a query to look for database objects like tables, keys e.t.c for the Context.
And if in model table name is modified using dataannotations or fluent api we see an issue in foreign key names.
Foreign Key name is dependent on table name and foreign key columns. In DbDatabaseExists method we generate a query to identify existence of database objects for the context. And inside the same method for ForeignKey names we refer AssociationSet of StoreItemCollection
that we receive in DbDatabaseExists. But the problem is we are not receiving AssociationSet with correct details, it shows the table name same as class name instead of name which was specified in data annotation or fluent api. This results in wrong Foreign
Key name to be searched. But create database object queries are getting generated correctly.
And as there is difference in foreign key names that were used while creating and verifying, provider gets mislead that database is not present in backend. And thus, tries to create database objects. And fails with Table or View already exists.
So, our issue will get resolved if AssociationSet is correctly updated with data annotation or fluent api table names.