Migrating to .NET Core: NuGet Package Dependencies

There are a few road blocks from migrating to .NET Core.  One roadblock is .NET Framework API’s that are not included in NETStandard2.0.  Another, is NuGet Package dependencies.

I’ll cover the API surface in another post, but for this post I want to show you a couple quick ways you can check if your NuGet package dependencies are compatible with .NET Core.

Checking NuGet.org

If you head over to NuGet.org and search for the package you depend on, there you can click to expand the Dependencies heading which will list all the targets.  Here’s an example of the MediatR package.

You can see which Platforms and versions of .NET Standard it supports.  And for each target ,which dependencies it has under that target.

I Can has .NET Core

The folks at Octopus Deploy released icanhasdot.net.  Here’s what how it works:

Upload your project’s packages.config, project.json, paket.dependencies and *.csproj files for analysis and we will build a visualization of the packages and whether .NET Standard versions are available on nuget.org

Give it try to see which NuGet packages you consume that are targeting .NET Standard.

Another interesting feature on the site is the Statistics page which shows Unsported and Supported packages that have been scanned.  I really am amazed how many library authors picked up on and supported .NET Standard.

Dependency Roadblocks

If find yourself blocked from migrating to .NET Core because of dependencies on certain NuGet packages, I’d love to hear about which ones? Also, if you were blocked but found an alternative package, let me know in the comments section or on Twitter.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

EF Core: Logging Lazy Loading

Entity Framework Core: Logging Lazy LoadingIf you are planning on migrating from Entity Framework 6.x to Entity Framework Core, there is likely one major road block: Lazy Loading.

In most circumstances I don’t think lazy loading is a good idea.  If you were using Entity Framework, you may be using Lazy Loading unintentionally since it’s built in by default.

Eager Loading

To eager load a related entity, you specify the related entity to be populated with the Include() method.  This is applicable in EF and EF Core.  However in Entity Framework 6.x, if you do not Include() a related entity, and access that navigation property, but default it will be lazy loaded.

Meaning a SQL statement will occur to load the related entity.  If you are iterating over a collection, this is where the N+1 comes from.

I assume this is why Entity Framework Core held out until 2.1 before providing a way to lazy load related entities since it’s now an opt-in.

Migrating

As mentioned, Entity Framework Core 2.1 now supports Lazy Loading as an opt-in.

I don’t recommend turning this on from a fresh project, but it may be applicable if you are migrating from Entity Framework 6.x to EF Core.   You can get pretty far with your existing LINQ queries without having to rewrite a large portion of your app.

Enable Lazy Loading

I don’t want to re-write the docs on how to enable Lazy Loading, so check them out.  However, I do want to show my preferred method and strategy that if you enable lazy loading, that you can log when it occurs.

This will provide you insights about where in your existing LINQ you are not calling Include() and eager loading the related entity.

First, to enable lazy loading, I’m going to add a param of Action<object, string> that will be injected into your entity by Entity Framework.  If the related entity being accessed is null, I’m going to Load the related entity, but also log out to the Console.  Obviously you would be using the logging tool you prefer, for this demo I’m just creating a console application.

Demo

Here’s a simple console application that first inserts a parent entity with two children. Then on the first call it does not Include() and will force lazy loading, which in turn will be logged to the console.  In the second call, Include() will be called and no lazy loading occurs.

Migration Comments

Have you migrated from Entity Framework 6.x to Entity Framework Core?  I’d love to hear about it in the comments or on Twitter.

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Roundup #3 – VS Live Share, ML.NET, Desktop .NET Core, EF6.3 on .NETCore3, Hyper-V Android Emulator

Since this week was Microsoft Build 2018, these were the top 5 things that came out of it for me.  Obviously I’m leaning towards the topics that affect me the most.  I’d love to hear what you found most interesting.  Let me know in the comments or on Twitter.

 

Visual Studio Live Share

If you work remotely or want to screen share with a co-worker in another office, you know how terrible most of current solutions are.  VS Live share was announced in preview back in November 2017 and is now available.

It doesn’t matter what type of app you’re building, what language you’re programming in, or what OS you’re on: when you need to collaborate, Live Share will instantly share your project with a teammate. Edit and debug together in real time without teammates needing to clone a repo or set up their environment.

Link: https://www.visualstudio.com/services/live-share/

 

.NET Core 3 to support WinForm, XAML & UWP

At Microsoft Build Live today, we are sharing a first look at our plans for .NET Core 3. The highlight of .NET Core 3 is support for Windows desktop applications, specifically Windows Forms, Windows Presentation Framework (WPF), and UWP XAML. You will be able to run new and existing Windows desktop applications on .NET Core and enjoy all the benefits that .NET Core has to offer.

Link: https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/

 

Introducing ML.NET: Cross-platform, Proven and Open Source Machine Learning Framework

Today at //Build 2018, we are excited to announce the preview of ML.NET, a cross-platform, open source machine learning framework. ML.NET will allow .NET developers to develop their own models and infuse custom ML into their applications without prior expertise in developing or tuning machine learning models.

ML.NET was originally developed in Microsoft Research and evolved into a significant framework over the last decade; it is used across many product groups in Microsoft like Windows, Bing, Azure, and more .

Link: https://blogs.msdn.microsoft.com/dotnet/2018/05/07/introducing-ml-net-cross-platform-proven-and-open-source-machine-learning-framework/

 

Entity Framework 6.3 on .NET Core 3

At Microsoft Build 2018 they also announced that Entity Framework 6.3 will run on .NET Core 3.  This is pretty big news if you want to migrate to .NET Core but have giant road block of Entity Framework and can’t easily move to EF Core.

Hyper-V Android emulator support

Today, at Build 2018, we announced a preview of the Google Android emulator that’s compatible with Hyper-V, available on the Windows 10 April 2018 Update. This enables developers with Hyper-V enabled on their machines to use a hardware accelerated Android emulator, without needing to switch to Intel’s HAXM hypervisor. Amazing work was done by the Windows Hyper-V team, with help from the Xamarin team, to make to this happen.

Link: https://blogs.msdn.microsoft.com/visualstudio/2018/05/08/hyper-v-android-emulator-support/

 

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.