Overview
NuGet.Services.Entities is the foundational domain model library for NuGet Gallery. It contains every Entity Framework entity class, supporting enum, base interface, and entity-level extension method that maps directly to the SQL Server database schema used by the Gallery and its related services. No application logic or data access code lives here — only the plain object graph that EF6 works with.
The two primary entity hierarchies are the package model and the account model. The package model centers on PackageRegistration (the stable identity record keyed by package ID) and Package (individual version records). The account model centers on User, with Organization extending User via Table-Per-Type (TPT) inheritance. All entities implement the marker interface IEntity, which enforces a single integer primary key convention (Key) across the entire schema.
The library targets both net472 and netstandard2.1, allowing it to be consumed by the ASP.NET Framework Gallery web application as well as .NET Standard-compatible background jobs. It ships as an internal NuGet package versioned with the common GalleryPackageVersion build property and has no internal project-to-project references — it is a leaf-level dependency that other projects reference but does not reference any of them.
Role in System
Package Domain
PackageRegistration anchors a package ID and its owners. Each Package record represents one version, carrying metadata fields, status flags, signing info, deprecation links, vulnerability ranges, and symbol package associations.Account Domain
User is the base account type. Organization extends it via TPT inheritance and adds member/admin tracking through the Membership join entity. Credentials, security policies, certificates, and federated credential policies all hang off User.Security Model
Credential covers API keys, username/password, and external (MSA / Entra ID) credentials. Scope restricts a credential to specific package IDs and allowed actions. FederatedCredentialPolicy enables keyless publishing via OIDC tokens from Entra ID service principals or GitHub Actions workflows.Namespace Reservation
ReservedNamespace records prefix or exact-match reservations that grant the IsVerified badge on matching PackageRegistration entries, preventing squatting on well-known package ID patterns.Key Files and Classes
Dependencies
NuGet Package References
Internal Project References
None.NuGet.Services.Entities has no internal project-to-project references and is a leaf dependency in the solution graph.
Notable Patterns and Implementation Details
IEntity as the universal key contract. Every entity in the library implements IEntity with a single int Key { get; set; }. This allows generic repository and service patterns in consuming projects (NuGetGallery.Core) to operate on any entity type without knowing its concrete class.TPT inheritance for Organizations.
Organization extends User using Entity Framework’s Table-Per-Type (TPT) pattern. The Users table holds all accounts; a separate Organizations table adds organization-specific columns. This design means any code that accepts a User can transparently handle both users and organizations, while organization-specific features (member lists, admin/collaborator projections) are only accessible on the Organization subtype.HasReadMe stores false as NULL. The HasReadMeInternal column stores null for false to avoid updating existing rows when the feature was introduced. The public HasReadMe property normalizes null to false via the NotMapped wrapper.FederatedCredential.Identity enforces replay prevention. The Identity field stores the unique token identifier (jti or uti claim) from an OIDC token. A unique database constraint on this column prevents the same token from being accepted twice, even after the issuing FederatedCredentialPolicy is deleted (the foreign key to the policy is intentionally not a hard FK constraint).UserStatus value 1 is intentionally unused. The enum skips from Unlocked = 0 to Locked = 2, mirroring the pattern in PackageStatus and reserving value 1 for a potential future Deleted status.