Writing custom visualizer for Linqpad 6
I want to upgrade my custom visualizer to support LINQPad 6 and have some questions about it. Currently it references LINQPad nuget. Do I need to now reference LINQPad.Runtime instead?
Is there a way to support both LINQPad 5 and 6 from a single nuget package ?
Comments
Add a reference to the LINQPad.Reference NuGet package - this contains reference assemblies for both versions of LINQPad.
To create a NuGet package that works for both LINQPad 5 and 6, you must instruct VS to include assemblies for both .NET Framework (for LINQPad 5) and .NET Core (for LINQPad 6). Start by creating a multi-targeting project as follows:
When you build, VS will automatically create a NuGet package whose lib folder contains both net46 and netcoreapp3.0 subfolders (net46 for LINQPad 5 and netcoreapp3.0 for LINQPad 6).
If you need to do anything differently for LINQPad 5 vs 6, use the conditional compilation symbol defined in the project file above (NETCORE).
Does the above approach works if I want to use WinForms instead of Wpf?
Yes: add
to your project file and add net46 references to System.Drawing and System.Windows.Forms.
What is object that is returned by
Util.CurrentDataContext
? Previously it wasDataContextBase
but that type is missing from the .net core version of theLINQPad.Reference
library.In LINQPad 6, the built-in data context drivers have been completely decoupled from the runtime, so LINQPad.Runtime now has no concept of DataContextBase (which was based on LINQ-to-SQL's DataContext class).
A benefit of this decoupling is that Util.CurrentDataContext now works for queries that use a different driver. For example if your query uses the built-in Entity Framework Core driver, Util.CurrentDataContext will return a DbContext object (whereas in LINQPad 5, it would return null). The same applies for third-party drivers.
If you want to access properties of Util.CurrentDataContext, the safest option is to use dynamic binding or reflection.
I see. How does Linq to SQL work in Linqpad 6 ? As I saw it's not supported by .net core
That's right - they removed LINQ-to-SQL for .NET Core. LINQPad uses a forked version:
https://github.com/albahari/LinqToSQL2
I guess there is no NuGet package for it right ?
There's no NuGet package. Is there a scenario that you can't easily solve with dynamic binding?
The current version of my visualizer depends on
System.Data.Linq
so I would need to make some changes to make it work again with dynamic bindingLet me know if you run into any blocking issues with dynamic binding (such as having to implement an interface).
Is EF 6 or 5 still supported by LINQPad 6 ?
LINQPad 6 does not support EF 5 or 6. EF 5 is .NET Framework-only, so that will never be an option. MS have recently released EF 6.3 for .NET Core, so it would be possible in theory to write a EF 6.3 driver for LINQPad 6, but it would only work for EF 6.3 projects that target .NET Core rather than .NET Framework.
Looks like there is no way to get the command from an iqueryable instance: Add interceptor on an existing DbContext item so I won't be able to make the visualizer work unless the user creates the context manually and adds an interceptor in the
OnConfiguring
methodMaybe you can provide some kind of hook where either users or visualizer author can add options while the
DbContext
is being created in theOnConfiguring
method ?Or wait for EF Core 5 which solves the issue of getting command from
IQueryable
@JoeAlbahari I have a nuget package that i'm trying to update to support both. The one thing I'm stuck on is PanelManager doesn't seem to be public in the new LinqPad.runtime package? Is there a recommendation?
https://github.com/NMyVision/LinqPad.JsonVisualizer/blob/master/src/JsonVisualizer/JsonVisualizer.cs#L54
Nevermind, figured it out.
In this case, you don't even need the conditional:
tv.Dump(title)
will work for both LINQPad 5 and 6.The reason for not being able to access PanelManager is that LINQPad.Runtime does not have any desktop dependencies - those are now in LINQPad.Runtime.UI. Should it be necessary, I can publish LINQPad.Runtime.UI to NuGet, too.