Entity Framework support in Rider 2018.1

A fresh build of Rider 2018.1 EAP just landed, adding Entity Framework support! Rider adds functionality to enable migrations, add a migration, get migrations, update the database and more! On Windows, Linux and macOS! Let’s check this out, shall we?

Initializing Entity Framework and enabling migrations

After installing the EntityFramework NuGet package, we can initialize Entity Framework in our project from the project context menu, under Tools | Entity Framework | Initial setup.

Initialize Entity Framework configuration

After confirming we want to initialize Entity Framework, Rider will add the necessary entries into our App.config or Web.config file: the entityFramework configuration section is registered and added, as well as a database connection.

Of course, we will need a model and DbContext to start with. For demo purposes, let’s use this simple model:

Next, we can Enable Migrations, again from our project’s Tools | Entity Framework context menu, which will execute Entity Framework’s Enable-Migrations command under the hood. We can provide several options to Entity Framework, such as the folder where migrations should be stored, whether we want to enable automatic migrations (or not), the projects and connection settings to use, …

Enable migrations for Entity Framework

In case you wonder about the log level displayed in this dialog: it controls the verbosity of the log that is displayed after executing an action. This can help troubleshoot, e.g. when the current project has build errors and such.

Adding migrations

Once we’ve enabled migrations (either via Rider or by opening an existing project with database migrations enabled), we can create additional migrations! As you may have guessed by know, we can do this from our project’s Tools | Entity Framework context menu, then Add migration. We are presented with similar options again, to fine-tune the Entity Framework command that will be executed behind the scenes.

Add Entity Framework migration

Migrations will be created in the folder that was specified when enabling migrations.

Update database

After making changes to our Entity Framework model, we may want to update our database to reflect the new model. Migrations can be executed against our database using our project’s Tools | Entity Framework | Update Database context menu.

We’ll have to select the target migration we want to apply to the database. No worries: this field comes with code completion. Other options are available as well, making it possible to, for example, use a different connection name and run the database migration against a development or staging database.

Update database running Entity Framework migration

Rider includes DataGrip functionality, letting us work with our tables, views, stored procedures as well as our data (tip: check the Rider database support series to learn more). This lets us immediately see the result of updating the database!

DataGrip exploring Entity Framework updates

Using the data source’s Diagrams | Show Visualization context menu (Ctrl+Alt+Shift+U in the Visual Studio keymap), we can retrieve a nice visualization of how our tables are related.

Entity Framework database diagram via DataGrip tools in Rider

Now back to Entity Framework! When updating the database, we do not have to run it against a database. We can also use the Script option and look at the script that will be executed against the database to update from a source migration to a target migration.

Update database to script window

This script file can then be stored in version control, executed against the database manually, and so forth.

Get migrations

At some point during our development cycle, we may want to check which Entity Framework migrations have been applied to the target database. From our project’s Tools | Entity Framework | Get migrations context menu, we can do just that! Rider will connect to the specified database and query for migrations that were applied:

Get migrations that were applied against our database

Current limitations

We plan to support Entity Framework 6.0, 6.1 and 6.2, however currently only Entity Framework 6.2 is supported – on Windows, Linux and macOS. While Entity Framework integration will work for most projects, it may not work as expected on all projects. If you encounter any issues, please let us know through our issue tracker.

Note it’s also possible to work with Entity Framework Core from Rider‘s built-in terminal.

Give the latest Rider 2018.1 EAP build a try! We’d love to hear your feedback!

This entry was posted in How-To's and tagged , , , , . Bookmark the permalink.

36 Responses to Entity Framework support in Rider 2018.1

  1. Denis Marinov says:

    I’m not sure if this is the right place, but I wanted to ask few things. I’m mostly programming in C/C++, Lua, PHP and JavaScript, using Jetbrains, and just to refresh my C# skills I wanted to see if Rider could be better option than VS. The first thing I happen to notice were the icons and the IntelliSense dropdown. It’s quite the same as in VS. The code style settings for Microsoft’s languages are looking different from other languages. You also miss “apply” button for saving things in the settings. You can only use the “save” button and then you have to return again if u need to change something else, cause the window closes itself. They’re no gutter icons for running test, only via the toolbar.

    Are all of these gonna change in the upcoming release?

    • Any location works to ask questions :-)

      > The first thing I happen to notice were the icons and the IntelliSense dropdown. It’s quite the same as in VS.

      The IDE may be different, but there are certain icons and elements people recognize as a class or method, so it’s probably good that these look similar.

      > The code style settings for Microsoft’s languages are looking different from other languages.

      These are adopted from ReSharper and Visual Studio. They can be tweaked, but since Rider builds on top of ReSharper we are exposing the .NET language settings from ReSharper.

      > You also miss “apply” button for saving things in the settings. You can only use the “save” button and then you have to return again if u need to change something else, cause the window closes itself.

      Would you mind logging a feature request on https:/youtrack.jetbrains.com/issues/RIDER#newIssue ?

      > They’re no gutter icons for running test, only via the toolbar.

      They should be, but it depends on the unit test framework you are using. For example for xUnit and NUnit, this should work out of the box. For MSTest, you may need some extra steps (find MSTest in this post: https://blog.jetbrains.com/dotnet/2017/09/04/rider-2017-2-eap-brings-net-core-2-0-mstest/)

      • Denis Marinov says:

        Thank you for the quick respond. At least the icons for files, folders etc. should be the same as every other Jetbrains project, I think, but like you said Rider is build on top of ReSharper.

        As for the MS languages goes, could that be separated? I don’t get a preview of how the code may look, like it is with other languages, or at least it doesn’t show every time.

        When will be the 2018.1 update release?

        • Denis Marinov says:

          One thing I forgot. I don’t see any of the MS languages have live templates, and I just wanted to add Console.ReadLine() to C#. Is that possible?

        • Matthias Koch says:

          Hi Denis,

          usually there should be a preview for all settings. Is there any specific entry, where you miss it?

          The reason why code style settings for C# or F# look a bit different, is because they are based on the ReSharper backend. Meanwhile, code style settings for JavaScript or JSON are based on WebStorm.

          • Denis Marinov says:

            I think it was a glitch that happen. I’m seeing it now.

            I did noticed that. I’m new to Rider and for someone who uses Clion and other Jetbrains projects on daily base, Rider looks quite different. That’s why I wanted to see if that’s gonna change any time soon, but since it has to do with ReSharper maybe it needs to stay that way.

  2. Denis Marinov says:

    Thank you for the quick respond. At least the icons for files, folders etc. should be the same as every other Jetbrains project, I think, but like you said Rider is build on top of ReSharper.

    As for the MS languages goes, could that be separated? I don’t get a preview of how the code may look, like it is with other languages, or at least it doesn’t show every time.

    When will be the 2018.1 update release?

    • Release will be in the next weeks.

      As for the code style settings, I have pinged someone on the team to check this.

      • Denis Marinov says:

        Okay, thank you! I think you can reply on the top one and delete this. I start to hate the the small reply button.

        • Denis Marinov says:

          You can delete this entire section, cause it’s kinda double. You can put your comment beneath the above one, that way you’ll have a nice tree :). I keep forgetting to use the reply button.

  3. Adam Williams says:

    > Note it’s also possible to work with Entity Framework Core from Rider‘s built-in terminal.

    I assume the GUI integration doesn’t support EF Core?

  4. Burak Tozkoparan says:

    Tools | Entity Framework | Initial setup | or the other commands does not show a pop dialog and nothing happens. On mac 2018.1 Is there something i do wrong or is this a bug? I am in the evaluation period..

  5. Vinicius Moraes says:

    Hi, don’t know why, but my rider disables the tools | entity Framework options. I have 2 projects on my solution, 1 for the views, and other (with the entity ) for data. The command line ‘dotnet ef’ does not work. In VS the solution runs OK.

    • Is this EF6 or EF Core?

      • Vinicius Moraes says:

        EF Core. I’ve just read that it only support via terminal. But it does not work also…

        • The terminal usually opens in the solution folder, you may have to cd into the project folder for dotnet ef to work.

          • Vinicius Moraes says:

            I did that, and did not work. I was thinking it could be a nuget missing or something, but I don’t know because it works on VS.

            • What is the error you are seeing?

              • Vinicius Moraes says:

                ‘No executable found matching command “dotnet-ef”‘. I’ve installed the codeGenerations.tools nuget packaget shown on jetbrains tutorial. Followed all steps and keep getting this error. Just to try, I’ve switched to the other’s project directory and run the command, and it recognizes, but when I try to make a migration : “Your target project ‘Your target project ‘CCS’ doesn’t match your migrations assembly ‘CCSData’. Either change your target project or change your migrations assembly.
                Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly(“CCS”)). By default, the migrations assembly is the assembly containing the DbContext.
                Change your target project to the migrations project by using the Package Manager Console’s Default project drop-down list, or by executing “dotnet ef” from the directory containing the migrations project.
                “. Same nuget installed on both projects (for testing). Also run “dotnet restore”, closed the IDE, and nothing.

              • Vinicius Moraes says:

                It worked! Many thanks. I’ve just put on Startup.cs the second option provided on the link.

  6. Darren Oster says:

    Great news that this has been added. The biggest issue is that the Config File dropdown selects all (e.g) web.config files in the project, and if there are multiple web.config files, it’s just trial and error to select the right one. Please add paths to this list!

Leave a Reply

Your email address will not be published. Required fields are marked *