Edge of the Web: Entity Framework Core: The Future of EF for ASP.NET Core

Play Edge of the Web: Entity Framework Core: The Future of EF for ASP.NET Core

The Discussion

  • User profile image

    Hi, thanks for the video.

    I have a question regarding migrations. In this demo you had all the staff in single project, so when you were generating migrations, the code was added to this project. But what happens if I implement my persistence layer in a separate assembly and want everything related to data access to stay in this assembly (including migrations)? In other words, how do I generate migrations in a project different to Web App project?

  • User profile image

    @andriysavin: I've done it with separate projects in a real-world application. The location of the models are identified by their namespace (which can be in a referenced assembly from another project) and the migrations can live away from the web project.

    In Solution Explorer, the default startup project would typically be your web project. In the Package Manager console, you can define a different default project to run migration commands in. 

  • User profile image

     @shahedC Great, thanks!

  • User profile image

    Hi Shahed,

    thanks for this brilliant tutorial.

    With EF7 is it still valid to use Generic Repository and Unit of Work Pattern

    Many thanks


  • User profile image

    @zaktecs: check out this Q&A on StackExchange that addresses your question in detail: 

    * http://programmers.stackexchange.com/questions/314266/are-repositories-needed-any-longer-in-asp-net-5-ef7

    It references the official ASP .NET Github: 


    There's also a mention of a response from Rowam Miller:



    Rowan says: "It's really up to you. There are two main reasons you may want to introduce a repository which are not handled by DbContext:

    * Removing any strong coupling between your app logic and data access layer. Though in reality, even with this abstraction it is very difficult to swap out a data access layer unless you build and test for multiple data access technologies right from the start.

    * Constraining the operations that the app layer can perform on the database. DbContext exposes IQueryable so the app can compose any query allowed by LINQ. Repositories that don't return IQueryable can help you control what is sent to the database.

    Ultimately it comes down to a philosophical/style/preference decision. Many apps have been built successfully using either approach."




Conversation locked

This conversation has been locked by the site admins. No new comments can be made.