1

I'm trying to deploy my ASP.NET MVC5 website to test following this tutorial: https://learn.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?

Flexabust Bergson
  • 732
  • 14
  • 34

1 Answers1

2

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.

Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • I already have app.config, should it be the exact same as the Web.config? Did the steps, but it does not work. Running Update-database , I see no migrations to be run in `PMC`. I'll add my app.config, but Web.config is much longer – Flexabust Bergson Sep 14 '17 at 08:50
  • @FlexabustBergson Add `` right after ``. Did you mark as StartUp Project AND Default Project in PMC? https://stackoverflow.com/a/26882750/3850405 – Ogglas Sep 14 '17 at 09:01
  • What error message do you get when running `Update-Database`? – Ogglas Sep 14 '17 at 09:10
  • No error, just it says that there are no explicit migrations to be run(it's in french). – Flexabust Bergson Sep 14 '17 at 09:11