HasDbFunction to an otherwise unmapped entity causes strange migration behavior #25133
Labels
area-migrations
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
File a bug
Apologies for my inability to describe this better in the title.
I have a class that I'm using to map to a TVF. It is configured as a keyless entity. It is not used for any other purpose and I do not need to map it to a table or view.
I initially migrated the model including seed data and then created the database from that migration.
Then I manually added a Table-Valued Function to the database. Running my demo, the mappings for the TVF work as expected and I can use them in queries.
The issue is related to migrating this model. I wanted to have a clean slate and include the functions in their own migration file.
Therefore, I deleted the migrations folder completely and then ran add-migration init. The resulting migration looked great. The class that the TVF was mapping to was not being picked up for table creation.
Next I needed an empty migration for the sake of providing the SQL to create the function. When I ran add-migration a second time, rather than empty UP and DOWN methods, migrations added "DROP TABLE" in UP and "CREATE TABLE" in DOWN for the table that was inferred by the class I defined for the mapping.
What I expected of course was an empty migration file.
Include your code
Here is the second migration file. The rest of the repo is on github at: https://github.com/julielerman/MappingDemo/tree/tvfonly
I have experimented with this problem numerous times always with the same result. To be clear, I am literally running add-migration twice in a row without making any changes.
Thanks for either pointing out what I have done wrong (and sorry for wasting your time in addition to my own :( ) or confirming that there ism, indeed, something fishy going on here.
Include provider and version information
EF Core version: 5.0.7
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.10.2
The text was updated successfully, but these errors were encountered: