Pergunta

I have google'd the crap out of this problem, I cannot find a solution.

Using EF code first approach against a domain assembly, being consumed by a .net web application.

in the domain project there is a app.config, in there I have the following connection string for EF

<connectionStrings>
<add name="DefaultConnection" connectionString="Initial Catalog=easyDayTea;Data Source=localhost;user=sa; password=12344321" providerName="System.Data.SqlClient" />

Then in the context class TeaDb.cs I have the following constructor:

public TeaDb()
        : base("name=DefaultConnection")
    {

    }

I have also tried just using "DefaultConnection" by itself in the constructor.

The problem:

Everything was fine until EF decided it wasn't going to take notice of additional classes/tables added to the context, so I removed EF from the project by deleting the migrations folder and empting the database of tables, then re ran enable-migrations and then the web application project to make EF do it's stuff to the database. However it did nothing!

When I run the web application though it works! and there is data (from the seed) in the tables, however not in any database i can see! It must be using a portable sql file, which doesn't make sense as I have it configured for a specific database / server by use of the configuration string.

I have also tried specifically specifying the connection string to use by doing a:

update-database -ConnectionStringName DefaultConnection -f

Still no joy.

If anyone could help me it would be amazing!

Thanks,

Xavier.

Foi útil?

Solução

You'll find your database at Users\[youruser]\[Name you passed in your context constructor].mdf

app/web.config are only used if they are in the main project, if you have an app.config/web.config outside your main project it will not be used (some templates add them, but they are meant to be used as an example).

Check this answer for a similar problem with EF4

Outras dicas

EF doesn't use the connection string from the app.config in the class library. It will use the connection string from the web.config in your web application. If you don't have the connection string defined in your web.config then it might be using conventions to attach the database with LocalDb in your App_Data directory.

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