Giter VIP home page Giter VIP logo

Comments (7)

tamasflamich avatar tamasflamich commented on May 18, 2024

Hi JonPSmith - Sorry for the late response. This shouldn't be a problem as Effort is not able to work when migrations is enabled, the suggested workaround is indeed to disable the initialiser.

What does happen if you indeed initialize your db explicitly?

from entityframework-effort.

JonPSmith avatar JonPSmith commented on May 18, 2024

Hi @tamasflamich,

The problem is if I call a null initialiser, e.g. Database.SetInitializer<MyDbContext>(null) then the next time Effort.EF6 accesses the database I get the exception I detailed in the first post above. I do this because some tests do access a real database directly and I want to make sure it doesn't look for migrations.

I have no migrations set on the database so its not that. I'm pretty sure Effort.EF6 doesn't support the calling of a null initialiser.

It would be great to have that fixed, but as a creator of a number of open-source libraries and working I know that time is limited. If you do get a chance to look at this/fix it then let me know.

from entityframework-effort.

JasonMisavage avatar JasonMisavage commented on May 18, 2024

@JonPSmith, I had a similar problem. I solved it by registering a System.Data.Entity.NullDatabaseInitializer<T> in my Dependency Injection container (Ninject, in my case) for production and the default System.Data.Entity.CreateDatabaseIfNotExists<T> initializer for unit tests. Then in the constructor of my EF context I just select whatever was registered, like so:
Database.SetInitializer(DIContainer.Get<IDatabaseInitializer<MyDbContext>>());

My use case isn't quite the same as yours since I don't have to think about migrations. But, you might consider a CustomInitializer for the tests that does the "Database.CreateIfNotExists()" line recommended in the error message and ignores any migration steps that the default initializer would try to do.

from entityframework-effort.

screaney avatar screaney commented on May 18, 2024

I'm having a similar issue, except my context is database first but with FluentAPI, so a hybrid model. My Context constructor always runs Database.SetInitializer<Context>(null);. That being the case, shouldn't Effort also apply this? I've tried putting it in my constructor, as well as in the unit test explicitly, however, I always get

Effort.Exceptions.EffortException: Database has not been initialized.

from entityframework-effort.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

Hello @screaney ,

We will try to look at this issue next week,

Best Regards,

Jonathan

from entityframework-effort.

michaelfoidl avatar michaelfoidl commented on May 18, 2024

Any news on this?

I'm having the same issue, although calling context.Database.CreateIfNotExists() is not an option for me, because I use a custom initialization infrastructure.

from entityframework-effort.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

Hello @michaelfoidl ,

Unfortunately no, we never found a solution.

The Effort in-memory database doesn't exist by default unlike your real database, so it currently requires the memory database to be created.

from entityframework-effort.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.