CsWin32 – Automatic PInvoke generation

CsWin32 is a compile time package generating Win32 PInvoke from a list of name including wildcard.

You add a reference to Microsoft.Windows.CsWin32 (pre release as of time of writing) and then you just have to create a text file named NativeMethods.txt alongside your project file.

During next build, a source generator will generate all requested PInvoke inside a Windows.Win32.PInvoke class. Each recursively needed type is also included.

A NativeMethods.json file can be used to customize generation

microsoft/CsWin32: A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

Beware: An issue with source generator in WPF projects requires you some hacking.

dotnet/datalab – a GitHub repository full of interesting EF Core extensions

A repository listing many projects related to extending EF Core.

I haven’t tested if these projects are robust implementations or even practical to use but it’s worth testing them if necessary and, why not, taking inspiration from them.

Some of them could be interesting:

Some extensions are already implemented in latest EF Core version but it can be useful for those stuck with old versions, I know something about it.

In a close domain, DapperLib/DapperAOT can also be very usefull. It’s a source generator that handle the heavy task of checking the SQL syntax before generating the Dapper code from attributes, all in AOT mode.

Entity Framework Core Remove method sometimes leads to an antipattern

A very simple way to delete entities in EF Core without preliminarily getting that entity. If we know its primary key, there is no need to do a get request, we just have to inform EF that the object is supposed to exist and deal with the case where it doesn’t exist. It’s obvious but very little used

More Efficient Deletes With Entity Framework Core | Khalid Abuhakmeh