DDD + Entityframework + Migrations + SQL Server

1

Hello, I have a Solution that I am implementing the DDD architecture with Entityframework, migrations and SQL Server! However, I am not able to connect to my local database when performing the migrations command: 'Updata-database'! I believe that only with the Connectionstring inserted in the API WebConfig I can already make this connection. That's right? or do I have to do another DDD setup?

Currently my Connectionstring is as follows:

 <connectionStrings>
    <add name="BWSDatabase" 
         connectionString="Server=localhost; 
                           Database=BWSDatabase; 
                           Data Source=DESKTOP-PTI280V;
                           Integrated Security=True;
                           Connect Timeout=30;
                           Encrypt=False;
                           TrustServerCertificate=False;
                           ApplicationIntent=ReadWrite;
                           MultiSubnetFailover=False" 
         providerName="System.Data.SqlClient" />
  </connectionStrings>

In this way the tables are generated locally in a stay of SLQ Server express in SQL Server Object Explorer, as well as the photo below ...

I'm using the layered DDD, which are:      1- Services (API Layer)      2- Application (Development Layer)      3- Domain      4- Infra (Layer where migrations are)

I'm running the command through the 'Package Manager Console', and only the tables are generated, and if I run the command again it displays the message that it has no update in migrations

Thank you in advance.

    
asked by anonymous 09.05.2018 / 23:51

1 answer

1

The connection string may be simpler than this, of course, depending on what you want, it's still worth some of the settings to go through. But there has to be reason.

Assuming you have created an instance of SQLEXPRESS you can use the windows authentication itself to connect to the database, your string would look like this:

<add name="MeuSistemaDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=BANCO_DE_DADOS;Integrated Security=true providerName="System.Data.SqlClient" />

A fact that may also be occurring in your case is that your context does not call the connection string, by default it will look for the connection string that has the same name, ie if its context calls MeuSistemaDbContext it will look for string de conexão with that name. If it has a different name you should pass that name to the constructor on your DbContext

Now, if you have 1 user and password to access the base, you can use the following string de conexão

<add name="MeuSistemaDbContext" connectionString="Database=BANCO_DE_DADOS; Server=.\SQLEXPRESS; User Id=USUARIO; Password=SENHA" providerName="System.Data.SqlClient" />
    
10.05.2018 / 03:27