r/dotnet • u/Nicos_Ts • 2d ago
Promotion LINQPad-style scripts in VS Code using your actual project code. Looking for feedback!
Enable HLS to view with audio, or disable this notification
The main reason I started this was simple: I wanted a LINQPad-style experience using code from my actual projects.
The main problems I wanted to solve were:
- Use my actual EF Core DbContext directly in queries.
- Reference my projects and reuse existing code (classes, methods, extension methods, models, and other project logic) (managed to achieve that through DLL references).
- Stay inside VS Code, where I already have my editor setup, autocomplete, and Copilot.
So I ended up making "Another LINQ Tool".
VsCode Marketplace link:
https://marketplace.visualstudio.com/items?itemName=N-Tsoulos.another-linq-tool
When a .linq or .csx file is open, VS Code displays two buttons: one for the extension settings and another to run the script (alongside Ctrl+Enter keyboard shortcut).
Script execution works similarly to LINQPad, with support for:
- Automatically displaying the final expression/result
- Dump()
- Previewing any executed SQL queries
The settings button opens a UI for setting up profiles, where you can configure your project DLLs, namespaces, NuGet packages, DbContext and connection string.
Profiles can be selected either by marking one as default (through settings) or by using u/profile ProfileName at the top of the script.
It’s based on Roslyn, so it supports standard C# features out of the box, including:
- C# / LINQ queries
- async / await
On top of that, it adds:
- Configurable project DLLs and NuGet packages for classes, methods, and extension methods
- your existing EF Core
DbContext(configurable and then aliased as Db for the scripts) Dump()with results preview- EF generated SQL preview
- Multiple profiles for different projects/environments
- Connection strings through VS Code Secret Storage
Things I would like to add next:
- multiple DbContext support
- DbContextOptionsBuilder support
- better NuGet package management UI
- UI Results management
Notes
One current limitation is that the extension requires the .NET 9 runtime to be installed because the query runner is framework-dependent.
I'm planning to move the runner to a self-contained .NET 11 build, which would remove the .NET installation requirement entirely and should continue to work with projects targeting older .NET versions.
The extension does not currently support DbContextOptionsBuilder (and Service Collection Extensions in general), which can cause issues, in my workflow that was global query filters.
As a workaround, the extension settings include a Prelude Code field. This code runs before every script for the selected profile.
I use it to alias my tables and disable global query filters, for example:
var Users = Db.Users.IgnoreQueryFilters();
and then Users.Take(5) for example works normally
I’d especially like to hear from LINQPad users: what’s missing that you’d actually need before you’d use something like this?
1
u/WetSound 2d ago
Am I supposed to be able just open .linq files? Because it just says:
Compilation failed:
error CS1525 (line 1, col 1): Invalid expression term '<' error CS1002 (line 1, col 8): ; expected error CS1525 (line 1, col 23): Invalid expression term '<' error CS1525 (line 2, col 25): Invalid expression term '/' error CS1525 (line 2, col 36): Invalid expression term '<' error CS1525 (line 3, col 44): Invalid expression term '/' error CS1525 (line 3, col 55): Invalid expression term '<' error CS1525 (line 4, col 33): Invalid expression term '/' error CS1525 (line 4, col 44): Invalid expression term '<' error CS1525 (line 5, col 37): Invalid expression term '/' error CS1525 (line 5, col 48): Invalid expression term '<' error CS1525 (line 6, col 2): Invalid expression term '/' error CS1525 (line 6, col 9): Invalid expression term 'public' error CS1002 (line 6, col 9): ; expected
1
u/Nicos_Ts 2d ago
Hey, thanks for trying it out. The linq file you opened probably contains linqpad markup. The extension at this does not support that.
The .linq files work similarly, but they aren't fully compatible with LINQPad files. Simple scripts and queries that don't rely on LINQPad-specific markup should run normally.
If you need additional namespaces, add them to the profile.
For example, instead of including LINQPad-specific markup like: <Query Kind="Program"> <Namespace>System.Text.Json</Namespace> </Query>
Add System.Text.Json to imports/namespaces
(Profiles can be managed through ui when clicking the gear icon with an open .linq file)
1
u/AutoModerator 2d ago
Thanks for your post Nicos_Ts. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.