Fuda.EntityFrameworkCore
0.0.1
dotnet add package Fuda.EntityFrameworkCore --version 0.0.1
NuGet\Install-Package Fuda.EntityFrameworkCore -Version 0.0.1
<PackageReference Include="Fuda.EntityFrameworkCore" Version="0.0.1" />
<PackageVersion Include="Fuda.EntityFrameworkCore" Version="0.0.1" />
<PackageReference Include="Fuda.EntityFrameworkCore" />
paket add Fuda.EntityFrameworkCore --version 0.0.1
#r "nuget: Fuda.EntityFrameworkCore, 0.0.1"
#:package Fuda.EntityFrameworkCore@0.0.1
#addin nuget:?package=Fuda.EntityFrameworkCore&version=0.0.1
#tool nuget:?package=Fuda.EntityFrameworkCore&version=0.0.1
Fuda
Fuda is a flexible tagging library for .NET applications.
It is inspired by the store/manager design used in ASP.NET Core Identity, and supports:
- tagging any entity type (
Taggable) - optional per-user tagging (
Tagger) - optional tag grouping by
Context(for example:skills,interests,bookmarks) - store abstraction so you can swap persistence implementations
- an Entity Framework Core implementation (
Fuda.EntityFrameworkCore) - batch tag loading APIs to avoid N+1 query problems
Core concepts
- Tag: the tag itself (
Name,NormalizedName, and ID) - Tagging: relation between a tag and a taggable entity (optionally with tagger and context)
- Taggable: the target entity to be tagged
- Tagger: optional actor that created/owns the tagging
- Context: optional category key for separating tag sets
Package structure
src/Fuda: core abstractions (ITagStore,ITaggingStore,ITagNormalizer,TagManager)src/Fuda.EntityFrameworkCore: EF Core stores, DI extensions, model configuration helpers
Quick start (Entity Framework Core)
1. Define your entities
public class Tag
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string NormalizedName { get; set; } = string.Empty;
}
public class Tagging
{
public int Id { get; set; }
public int TagId { get; set; }
public int TaggableId { get; set; }
public int? TaggerId { get; set; }
public string? Context { get; set; }
}
public class BlogPost
{
public int Id { get; set; }
public string Title { get; set; } = string.Empty;
}
2. Create your DbContext
Use FudaDbContext<...> as your base class and call ConfigureFuda.
using Microsoft.EntityFrameworkCore;
using Fuda.EntityFrameworkCore;
public class BlogDbContext : FudaDbContext<Tag, Tagging, object, BlogPost, int>
{
public DbSet<BlogPost> BlogPosts => Set<BlogPost>();
public BlogDbContext(DbContextOptions<BlogDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Tag>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.Name).IsRequired();
entity.Property(x => x.NormalizedName).IsRequired();
});
modelBuilder.Entity<Tagging>(entity =>
{
entity.HasKey(x => x.Id);
entity.Property(x => x.TagId).IsRequired();
entity.Property(x => x.TaggableId).IsRequired();
});
modelBuilder.ConfigureFuda<Tag, Tagging, int>();
}
}
3. Register Fuda in DI
using Fuda.EntityFrameworkCore;
builder.Services.AddFuda<Tag, Tagging, object, BlogPost, int>()
.AddEntityFrameworkStores<BlogDbContext>(
getTaggableIdFunc: post => post.Id);
AddEntityFrameworkStores also accepts property name overrides if your schema uses different names.
4. Inject and use TagManager
using Fuda;
public class PostsService
{
private readonly TagManager<Tag, Tagging, object, BlogPost, int> _tagManager;
public PostsService(TagManager<Tag, Tagging, object, BlogPost, int> tagManager)
{
_tagManager = tagManager;
}
public async Task AddTagsAsync(BlogPost post)
{
await _tagManager.AddTagAsync(post, "ASP.NET Core");
await _tagManager.AddTagAsync(post, "Tutorial", context: "category");
var tags = await _tagManager.GetTagsAsync(post);
await _tagManager.ReplaceTagsAsync(post, new[] { "dotnet", "web" });
await _tagManager.RemoveTagAsync(post, "web");
}
}
API overview
Add/Remove/Replace
AddTagAsync(taggable, tagName, context?)AddTagAsync(tagger, taggable, tagName, context?)RemoveTagAsync(taggable, tagName, context?)RemoveTagAsync(tagger, taggable, tagName, context?)ReplaceTagsAsync(taggable, tagNames, context?)ReplaceTagsAsync(tagger, taggable, tagNames, context?)
Read
GetTagsAsync(taggable, context?)GetTagsAsync(tagger, taggable, context?)GetTagCountsAsync(context?)GetTagCountsAsync(tagger, context?)
Search
GetTaggableIdsAsync(tagNames, context?)- Find entities that have all of the specified tagsGetTaggableIdsAsync(tagger, tagNames, context?)- Find entities tagged by the tagger with all of the specified tags
// Find blog posts that have BOTH "csharp" AND "dotnet" tags
var postIds = await tagManager.GetTaggableIdsAsync(new[] { "csharp", "dotnet" }, "tags");
Batch loading (N+1 prevention)
GetTagsForManyAsync(taggables, context?)GetTagsForManyAsync(tagger, taggables, context?)
Use batch loading when you need tags for many entities in list pages.
var posts = await context.BlogPosts.OrderByDescending(p => p.Id).ToListAsync();
var tagMap = await tagManager.GetTagsForManyAsync(posts);
// tagMap[postId] => IReadOnlyList<Tag>
Tagger and Context patterns
Tagger
Use tagger overloads to isolate taggings by user/account.
await tagManager.AddTagAsync(currentUser, post, "bookmark", context: "bookmarks");
var myTags = await tagManager.GetTagsAsync(currentUser, post, context: "bookmarks");
Context
Use contexts to keep independent tag namespaces on the same entity.
await tagManager.AddTagAsync(post, "C#", context: "skills");
await tagManager.AddTagAsync(post, "Featured", context: "status");
Normalization
TagManager uses ITagNormalizer to normalize names before creating/searching tags.
- default implementation:
UpperInvariantTagNormalizer - purpose: prevent duplicates like
csharpvsCSHARP
You can replace it in DI with your own implementation.
Using custom stores (without EF Core)
Fuda core is persistence-agnostic.
Implement these interfaces for your storage backend:
ITagStore<TTag, TKey>ITaggingStore<TTagging, TTag, TTaggable, TTagger, TKey>
Then construct/inject TagManager<...> with your store implementations and an ITagNormalizer.
Example project
A runnable sample app is available at:
examples/BlogApp
It demonstrates DI registration, EF Core mapping, batch loading, and tag display/filtering.
Development
From the repository root:
dotnet build
dotnet test
Test coverage
Collect coverage (Coverlet collector is installed in test projects):
dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults
Generate an HTML report with ReportGenerator (local tool):
dotnet tool restore
dotnet tool run reportgenerator \
-reports:"./TestResults/**/coverage.cobertura.xml" \
-targetdir:"./TestResults/CoverageReport" \
-reporttypes:"Html"
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Fuda (>= 0.0.1)
- Microsoft.EntityFrameworkCore (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
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.1 | 150 | 4/20/2026 |