Using LINQPad with Entity Framework / EF Core
LINQPad lets you query Entity Framework models that you define in Visual Studio. This provides instant feedback, as well as
enabling you to see the SQL that your queries generate (just click the SQL tab).
You can query Entity Framework models in both LINQPad 6 (for .NET Core / .NET 5) and LINQPad 5 (for .NET Framework).
Use LINQPad 6 if:
- You're using EF Core and your assemblies target .NET Core or .NET 5
Use LINQPad 5 if:
- You're using Entity Framework 6 or earlier, or
- You're using EF Core and your assemblies target .NET Framework
If you're using EF Core and your assemblies target .NET Standard 2.0, you can use either LINQPad 5 or 6, although
you'll get a better experience in LINQPad 6.
You can install and run LINQPad 5 and LINQPad 6 side-by-side.
- Create an Entity Framework data model in a Visual Studio project, and build.
- From LINQPad, click Add Connection (top left) and choose Entity Framework or Entity Framework Core in the bottom listbox.
Note that in LINQPad 5, the Entity Framework Core driver must first be downloaded - click View More Drivers and choose the EF Core driver
from the gallery.
- Click Browse and locate the assembly (DLL or EXE) that you built in step 1.
- Choose your typed DbContext/ObjectContext class.
- Choose an option on how to instantiate the data context. In LINQPad 6, click the Help me choose link for more information.
Confirm the remaining details, then click Test and then OK.
Your model will now show in the Schema Explorer. Right-click to start a new query:
If it works when clicking the Test button, but fails when running a query, it will most likely be picking up the wrong connection string,
based on the options you've chosen. Remember that if your connection string comes from an appsettings.json or app.config file, you must
specify a path to it in the box provided. You can see what connection string EF Core is using by running the following query:
Or with Entity Framework 6:
- You can return to Visual Studio at any time and rebuild - LINQPad will not lock your assemblies.
- LINQPad automatically refreshes the schema explorer and autocompletion cache whenever the assembly changes.
- If your assembly references other assemblies, LINQPad will pick up these, too, providing they either live in the same folder,
or are listed in the .deps.json file.