EfHashTagGenerator 0.0.2

dotnet add package EfHashTagGenerator --version 0.0.2
                    
NuGet\Install-Package EfHashTagGenerator -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="EfHashTagGenerator" 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="EfHashTagGenerator" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="EfHashTagGenerator">
  <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 EfHashTagGenerator --version 0.0.2
                    
#r "nuget: EfHashTagGenerator, 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.
#addin nuget:?package=EfHashTagGenerator&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=EfHashTagGenerator&version=0.0.2
                    
Install as a Cake Tool

Stand With Ukraine

EfHashTagGenerator

NuGet version (EfHashTagGenerator)

EfHashTagGenerator 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.

🛠 Usage

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

The tag #a1b2c3d4 is generated from a stable hash of the call site like:

MyClass.GetUsers:L42

🔧 How It Works

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

internal static class EfHashTagExtensions
{
    public static IQueryable<T> TagWithCallSiteHash<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 = GetHashTagByLocation(location);
        return query.TagWith(hashTag);
    }

    private static string GetHashTagByLocation(string location)
    {
        switch (location)
        {
            case "Test0.Main:L38": return "#c9c32584";
            // ...
            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 hashtag 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 156 5/22/2025
0.0.1 97 4/26/2025