开发者

How can I run SQL upon Database creation with EF 4.1 CodeFirst?

开发者 https://www.devze.com 2023-02-20 10:36 出处:网络
I want to utilize Elmah in my MVC application to store error messages, and I want to store the exceptions in my application\'s database.To do that I need to run the included DDL to create the Elmah ta

I want to utilize Elmah in my MVC application to store error messages, and I want to store the exceptions in my application's database. To do that I need to run the included DDL to create the Elmah tables and stored procs.

However, since my development database is recreated whenever my model changes (Via EF CodeFirst) I need the DDL to be run any time the database is recreated.

How would I go about doing this? The only place I could think to put this would be to add calls to run the Sql in the Seed() overridden method in my DbInitiali开发者_运维百科zer, but it doesn't seem completely appropriate since I am not seeding elmah, I am creating the structure for the schema to be created.

What is the most appropriate way to apply the DDL upon database recreation?


Using Seed method is usual approach to place custom SQL to execute after database is created. Its main purpose is to fill some initial data but developers use it for creating indexes, constraints, etc. so you can place there anything you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消