Home Can't Execute Code First Migrations in Web Deploy
Reply: 1

Can't Execute Code First Migrations in Web Deploy

Flexabust Bergson
1#
Flexabust Bergson Published in 2017-09-14 08:21:44Z

I'm trying to deploy my ASP.NET MVC5 website to test following this tutorial: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis

In the part about "Configure deployment for the application database" point 2, I need to check a box that is not avaible on my screen(Execute Code First Migrations). My problem being the following : I have an onion architecture, hence my project containing the context of Entity Framework is in a separate project (and I'm deploying the asp.net MVC 5 project), so that means I cannot enable-migrations in this project. I've also changed my connection strings to fit the name of my context as precised in this post : https://stackoverflow.com/a/32866872/4714502 . On the other hand, my DbSet have different names then my Entity Framework classes, would that be an issue? I did this because the syntax of my tables is quite awkward, and was a requirement (I did not want to use this naming convention in my application). Say for a table Web_Documents :

DbSet<Web_Documents> WebDoc { get; set; }

As for the architecture I have :

  1. Entities (POCO)
  2. Repository (context is here)
  3. Service
  4. UI (MVC) (Deploy here)

Dependencies go from 4 to 1.

And here is my app.config in Repository:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="PrincipalServerContext" connectionString="Data Source=SMRFG12APP13\SQLEXPRESS;Initial Catalog=PrincipalServerDB;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

My db's name is PrincipalServerDB and the context PrincipalServerContext Now I'm out of ideas, don't really know what else I can do?

Ogglas
2#
Ogglas Reply to 2017-09-14 08:42:08Z

Create an App.config file in the project containing the context and add your connectionString there. Match Web.config structure. Example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=YourDb Security=sspi;Pooling=false;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

After this set context project as StartUp Project, in PMC set it as Default project and after this run Update-Database. Now it will update.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.410668 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO