Pergunta

I want to use ELMAH with sql server on my ASP.net MVC 3 project, along with EF 4.3.

Is there a way I can have the sql script run automatically that creates the elmah tables?

I'm guessing that ef migrations might do the job but I haven't used them much yet.

I'm aiming for a solution where you can checkout the solution and run it straight up (to sqlexpress locally or full blown sql server on deploy) and have it just work without having to manually run the various helper sql scripts

Foi útil?

Solução

Add an empty code-based migration (just type add-migration ElmahSetup when there are no pending DB changes).

Then add calls to Sql() to run the elmah in the Up() method. To make the solution complete you have to add corresponding drop statements to the Down() method.

Outras dicas

I know this question was for EF 4.3, but if you are using EF 6.1 then there is now a nuget package that will initialize the Elmah table and procs for you: https://www.nuget.org/packages/Elmah.SqlServer.EFInitializer/. Add it to your web project. It will then use EF code first to create it for you. It adds an Initializer to your App_Start folder so you actually don't have to add any code. It will add a migration to your database to ensure it only gets added once.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top