Using LINQPad with Custom Entity Framework / EF Core Models

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 8 (for .NET 8/7/6/5) and LINQPad 5 (for .NET Framework).

Use LINQPad 8 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 8, although you'll get a better experience in LINQPad 8.

You can install and run LINQPad 5 and LINQPad 8 side-by-side.

Steps

  1. Create an Entity Framework data model in a Visual Studio project, and build.
  2. 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.
  3. Click Browse and locate the assembly (DLL or EXE) that you built in step 1.
  4. Choose your typed DbContext/ObjectContext class.
  5. Choose an option on how to instantiate the data context. In LINQPad 8, click the Help me choose link for more information.
  6. 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:

Entity Framework Schema TreeView

Troubleshooting

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:

this.Database.GetDbConnection().ConnectionString

Or with Entity Framework 6:

this.Database.Connection.ConnectionString

Additional Notes

  • 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.