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.
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:
public class ProductsContext : DbContext { public DbSet<Product> Categories { get; set; } } public class Product { public int Id { get; set; } public string Name { get; set; } }
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, …
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.
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.
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!
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.
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.
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:
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!
Denis Marinov says:
April 10, 2018I’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?
Maarten Balliauw says:
April 10, 2018Any 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:
April 10, 2018Thank 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:
April 10, 2018One 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?
Maarten Balliauw says:
April 10, 2018That’s being worked on, probably 2018.2.
Denis Marinov says:
April 10, 2018Okay! That would be great. Toch een prettige dag!
Matthias Koch says:
April 10, 2018Hi 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:
April 10, 2018I 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.
Denis Marinov says:
April 10, 2018Thank 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?
Maarten Balliauw says:
April 10, 2018Release 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:
April 10, 2018Okay, 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:
April 10, 2018You 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.
Adam Williams says:
April 16, 2018> 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?
Maarten Balliauw says:
April 16, 2018Only terminal at this time. Feel free to post a feature request via https://youtrack.jetbrains.com/issues/RIDER#newIssue
Adam Williams says:
April 17, 2018Thanks Maarten, voted on the issue someone else already made 🙂
Burak Tozkoparan says:
May 15, 2018Tools | 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..
Maarten Balliauw says:
May 15, 2018Is this using EF 6 or EF Core?
Burak Tozkoparan says:
May 15, 2018EF Core
Burak Tozkoparan says:
May 15, 2018I used “dotnet ef migrations add xxxxxx ” command from the terminal and it works fine as expected, it adds the autogenerated migration class..
Maarten Balliauw says:
May 15, 2018As mentioned in the post, this is currently for EF 6 only. For .NET Core, using the built-in terminal is the way to go (https://blog.jetbrains.com/dotnet/2017/08/09/running-entity-framework-core-commands-rider/)
Burak Tozkoparan says:
May 15, 2018Thank you for your answer. Sorry that i just started to try out the tutorial from the top to the bottom 🙂
Maarten Balliauw says:
May 15, 2018No worries 🙂 Hope you are enjoying Rider?
Burak Tozkoparan says:
May 15, 2018except than many templates missing (like web api,etc.) when compared to VS ,so far so good. I used VS+resharper for the last two years and I am a real fan of its’ auto import references and refactoring tool. In Rider, moreover, I really liked the decompiling of the referenced assemblies! I think I will choose this IDE for my team next month! But please more templates! I love them 🙂
Maarten Balliauw says:
May 16, 2018You can always install extra templates – Rider shares this with
dotnet install
. More info at https://blog.jetbrains.com/dotnet/2017/12/21/project-templates-rider-2017-3/(and a list of templates at http://dotnetnew.azurewebsites.net)
If you are missing any specific ones, can you request these through our issue tracker? https://youtrack.jetbrains.com/issues/RIDER#newIssue
Burak Tozkoparan says:
May 19, 2018Great news! Thank you for the information!
Vinicius Moraes says:
May 15, 2018Hi, 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.
Maarten Balliauw says:
May 15, 2018Is this EF6 or EF Core?
Vinicius Moraes says:
May 15, 2018EF Core. I’ve just read that it only support via terminal. But it does not work also…
Maarten Balliauw says:
May 16, 2018The terminal usually opens in the solution folder, you may have to
cd
into the project folder fordotnet ef
to work.Vinicius Moraes says:
May 16, 2018I 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.
Maarten Balliauw says:
May 16, 2018What is the error you are seeing?
Vinicius Moraes says:
May 16, 2018‘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.
Maarten Balliauw says:
May 16, 2018Those should be in the docs for EF. (e.g. this looks promising – https://github.com/aspnet/EntityFrameworkCore/issues/5900#issuecomment-387839236)
Vinicius Moraes says:
May 16, 2018It worked! Many thanks. I’ve just put on Startup.cs the second option provided on the link.
Darren Oster says:
June 7, 2018Great 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!
Maarten Balliauw says:
June 7, 2018Could you upvote this feature request? https://youtrack.jetbrains.com/issue/RIDER-15744
Bradley Landis says:
October 23, 2018I have a project with EF 6.2 on Rider 2018.2 and the Entity Framework option does not show under Tools. Is there something else I need to configure?
Maarten Balliauw says:
October 23, 2018Right now this is only available for EF 6.1.
Andrej O says:
February 20, 2019Can you please point me in the direction of some docs or something? I can’t get Rider to show the Entity Framework option under the Tools menu… I’ve been using EF 6.1.3, no success. Updated to EF 6.2, still nothing.
I’ve just updated Rider to 2018.3.3 and still nothing. I really don’t want to open VS every time I want to use migrations.
Maarten Balliauw says:
February 25, 2019Can you check https://youtrack.jetbrains.com/issue/RIDER-20226#focus=streamItem-27-3084428.0-0 ?
Andrej O says:
February 25, 2019Thank you.
You might want to consider adding this to the blog post/docs. 🙂
Maarten Balliauw says:
February 25, 2019Just put it in bold at the top of the post, thanks!
Jeff says:
February 20, 2019Ok. I am trying to get this to work.
I have a project where I have EF 6.1.0 on Rider 2018.3.3 and I’m not seeing the EF option under Tools. Do I need to do anything else?
Maarten Balliauw says:
February 25, 2019Can you check https://youtrack.jetbrains.com/issue/RIDER-20226#focus=streamItem-27-3084428.0-0 ?
Marcel Bradea says:
July 24, 2019Hi there, is the team working on adding in support for the upcoming .NET Core 3.0 Preview 8 release?
From the announcement of Preview 7 (https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-3-0-preview-7-and-entity-framework-6-3-preview-7/) it seems support was added for IDEs (Visual Studio specifically) (https://github.com/aspnet/EntityFramework6/issues/231) but command-line is not yet supported (https://github.com/aspnet/EntityFramework6/issues/1053).
For those of us using Rider as our .NET IDE, this means we are currently left dependent on you guys to update the Rider GUI to work with the new tooling – available in nightly releases.
Much appreciate you guys making sure to update the support for this to Rider to not leave us stranded without any way to run migrations on .NET Core 3.0 (ie: no MS command line support)
Maarten Balliauw says:
July 25, 2019Hi Marcel,
You can track https://youtrack.jetbrains.com/issue/RIDER-12403 which groups all of that EF work.
Marcel Bradea says:
September 6, 2019Thank you Maarten. I saw that this got marked as ‘nice to have’, but this is not the case for .NET Core 3.0 anymore because the EF 6 command-line migrations no longer work on .NET Core 3.0, and the MS team has no existing plans to do so (so no fix on the way anytime soon).
This means migrations now ONLY work from Visual Studio, adding a new dependency that’s blocking us from adopting .NET Core 3.0 on Rider – or forcing us to bring in Windows + Visual Studio back into the mix.
Here is the issue that tracks the work that enabled adding this to IDEs: https://github.com/aspnet/EntityFramework6/issues/231 – as well as the currently unplanned and regressed command line tools that no longer works on .NET Core 3.0: https://github.com/aspnet/EntityFramework6/issues/1053
Maarten Balliauw says:
September 7, 2019Feel free to upvote the issue and add a comment there (I just did as well).
Marcel Bradea says:
September 12, 2019Maarten your issue seems to be about database-first, not code-first migrations.
I’ve created a new issue here: https://youtrack.jetbrains.com/issue/RIDER-32813
Marcel Bradea says:
December 12, 2019Resurfacing this – migrations are broken on .NET Core 3.0 and 3.1 due to Microsoft’s drop of support for command line tools.
– https://youtrack.jetbrains.com/issue/RIDER-19973
– https://youtrack.jetbrains.com/issue/RIDER-32813?_ga=2.223357083.1882797263.1576189004-1498817148.1534174900
– https://github.com/aspnet/EntityFramework6/issues/1053#issuecomment-565211029
This is a critical functionality that is blocking us from mutating our database / making any system changes – or migrating to .NET Core 3.x.
Can you guys please resolve urgently?
Big thanks.
Eric Leija says:
March 4, 2020How does one set the startup project? a command line I’m used to using is:
add-migration SomeMigration -startupproject MyProjectName.Project
How to?