EfAbbreviationTagGenerator 0.0.2

dotnet add package EfAbbreviationTagGenerator --version 0.0.2
                    
NuGet\Install-Package EfAbbreviationTagGenerator -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EfAbbreviationTagGenerator" Version="0.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EfAbbreviationTagGenerator" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="EfAbbreviationTagGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EfAbbreviationTagGenerator --version 0.0.2
                    
#r "nuget: EfAbbreviationTagGenerator, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EfAbbreviationTagGenerator@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EfAbbreviationTagGenerator&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=EfAbbreviationTagGenerator&version=0.0.2
                    
Install as a Cake Tool

Stand With Ukraine

EfAbbreviationTagGenerator

NuGet version (EfAbbreviationTagGenerator)

EfAbbreviationTagGenerator is a Roslyn Incremental Source Generator that enhances EF Core LINQ query tracing by generating deterministic and consistent SQL query tags based on the call site abbreviations.

🛠 Usage

  1. Reference this generator from your project (as an analyzer NuGet package or project reference).
  2. In your LINQ queries, simply call:
query.TagWithCallSiteAbbreviation();
  1. The source generator will automatically emit:
query.TagWith("#mcgu42");

The tag #mcgu42 is generated from a abbreviation of the call site like:

MyClass.GetUsers:L42

🔧 How It Works

  1. Scans all invocations of TagWithCallSiteAbbreviation() in your codebase.
  2. Extracts:
    • File path
    • Method name
    • Line number
  3. Computes an abbreviation.
  4. Emits a helper class:

internal static class AbbreviationTagExtensions
{
    public static IQueryable<T> TagWithCallSiteAbbreviation<T>(
        this IQueryable<T> query,
        [CallerFilePath] string filePath = null,
        [CallerMemberName] string memberName = null,
        [CallerLineNumber] int lineNumber = 0)
    {
        var location = $"{Path.GetFileNameWithoutExtension(filePath)}.{memberName}:L{lineNumber}";
        var hashTag = GetAbbreviationByLocation(location);
        return query.TagWith(hashTag);
    }

    private static string GetAbbreviationByLocation(string location)
    {
        switch (location)
        {
            case "Test0.Main:L38": return "#tm38";
            // ...
            default: return location;
        }
    }
}

📝 Requirements

  • EF Core (uses .TagWith() internally)

📂 Output Location

Add the following code to your project file to add the generated code to the project folder to be able to find the source code by abbreviation later:

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

And then exclude it from compilation

<ItemGroup>
    
    <Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>


📃 License

Apache 2.0

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 467 7/24/2025
0.0.1 465 7/24/2025