0

I described the database through Fluent Api.

However, I want to use Database.EnsureCreated (); some additional SQL code was executed.

Where can i place it?

iluxa1810
  • 278
  • 3
  • 12
  • You can place it anywhere that is in-scope of the calling code. Am I understanding your problem correctly? – Robert Harvey Mar 09 '20 at 20:32
  • In other words, find a place to put the code, put it in an appropriate namespace, add the necessary `using` statements, and call it like you would call any other method. – Robert Harvey Mar 09 '20 at 20:34
  • @RobertHarvey You understood not quite right. I want that if the database was absent when creating the context, then Database.EnsureCreated (); it was created + executed by some SQL code. Can I override any DbContext method to achieve the goal? –  iluxa1810 Mar 09 '20 at 20:38
  • Sorry, but I still don't understand what you are asking. If you just want to execute your own SQL though EF core, [this explains how to do that.](https://learn.microsoft.com/en-us/ef/core/querying/raw-sql) – Robert Harvey Mar 09 '20 at 20:41
  • @RobertHarvey Some like https://stackoverflow.com/questions/21731889/add-database-trigger-with-entity-framework-code-first-migrations –  iluxa1810 Mar 09 '20 at 20:52
  • Why doesn't that post answer your question? – Robert Harvey Mar 09 '20 at 20:54

0 Answers0