dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.62k stars 1.96k forks source link

Document flowing annotations through the model to migrations #599

Open ajcvickers opened 6 years ago

ajcvickers commented 6 years ago

Specifically to show how the model can be annotated, the model differ can diff those annotations, and migrations operations can be created.

kroleigh commented 6 years ago

The first thing I'd like to see is how to prioritize object creation or specify dependencies. When generating the SQL script, the SQLGenerator will create table objects and then create foreign key constraints. However, when creating views, the body of the SQL will have dependencies on underlying tables or views. How can we provide this hint to EF?

In the customcodegenerator, I can change a CreateTable statement to a CreateView statement by testing for my new annotation IsViewAttribute. I can then extend m SQLGenerator to handle CreateView. What I don't see is how to specify that the table Zoologists needs to exist before the view vwSpecialists; and that, uspAuditData needs to exist before creating any table object with an Instead of Trigger. example: migrationBuilder.CreateProcedure(ProcedureType.StoredProcedure,"audit.uspAuditData"); migrationBuilder.CreateProcedure(ProcedureType.InsteadOfInsert,"dbo.customers"); migrationBuilder.DependencyMap.Add("dbo.customers","audit.uspAuditData");

update-database -script outputs in alpha order.