Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy 1.1.0

dotnet add package Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy --version 1.1.0
                    
NuGet\Install-Package Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy -Version 1.1.0
                    
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="Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy" />
                    
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 Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy --version 1.1.0
                    
#r "nuget: Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy, 1.1.0"
                    
#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 Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy@1.1.0
                    
#: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=Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy&version=1.1.0
                    
Install as a Cake Tool

Mecesoft.Data.EntityFrameworkCore.SqlServer.Tenancy

Mecesoft.Data 1.1.0 ile standart DbContext, IdentityDbContext ve Mecesoft.Repository uyumluluk katmanı desteklenir. Bu paket yalnızca row-per-tenant production collation/relationship doğrulaması için gereklidir; tenant kullanmayan veya DB-per-tenant uygulamalar bu pakete ihtiyaç duymaz.

Opsiyonel SQL Server production tenant collation doğrulama paketi.

Kapsam

Bu paket yalnızca SQL Server'a özgü ITenantCollationVerifier implementasyonunu sağlar. Ana Mecesoft.Data.EntityFrameworkCore paketi provider-neutral kalır ve bu pakete bağımlı değildir.

Kullanım

protected override ITenantCollationVerifier? TenantCollationVerifier
    => SqlServerTenantCollationVerifier.Instance;

İsteğe bağlı DI kaydı:

services.AddMecesoftSqlServerTenantCollationVerification();

DI kaydı context'i otomatik olarak değiştirmez; context, verifier'ı TenantCollationVerifier üzerinden açıkça kullanmalıdır.

Doğrulama kuralları

  • Tenant property gerçek EF table/column mapping metadata'sından çözülür.
  • Custom schema, quoted identifier ve HasColumnName desteklenir.
  • Explicit schema yoksa SQL Server'ın gerçek unqualified çözümlemesi OBJECT_ID/schema metadata'sı üzerinden bulunur; hardcoded dbo fallback'i güvenlik kanıtı olarak kullanılmaz. Aynı tablo adı farklı şemalarda bulunuyorsa yalnızca EF'nin gerçekten eriştiği şema doğrulanır.
  • Yalnızca kullanıcı tablosu (sys.objects.type = 'U') kabul edilir.
  • Yalnızca nvarchar kabul edilir. varchar, char, nchar, text, ntext, alias/user-defined type reddedilir.
  • Kayıpsız Unicode için yalnızca nvarchar + _BIN2 kabul edilir. Bütün varchar kombinasyonları, _BIN2_UTF8 dahil, reddedilir.
  • sys.columns.max_length doğrulanır: nvarchar en az 256 byte veya MAX olmalıdır; daha küçük kolonlar fail-closed reddedilir.
  • _CS_AS, _CS_AI, _CI_*, _BIN2_UTF8 ve legacy _BIN reddedilir.
  • Computed ve encrypted kolonlar reddedilir.
  • View, synonym ve diğer non-table object türleri reddedilir.
  • Model foreign key delete action'ları sys.foreign_keys/sys.foreign_key_columns ile schema-qualified olarak karşılaştırılır. Modelde bulunmayan veya modelle uyuşmayan ON DELETE CASCADE/SET NULL/SET DEFAULT fail-closed reddedilir. Eksik/ambiguous metadata doğrulamayı durdurur.
  • Catalog sorgusu parametreledir; identifier string interpolation kullanılmaz.

Trailing-space exactness

SQL Server nvarchar = karşılaştırmaları trailing space'leri yok sayar. _BIN2 bunu değiştirmez. Paket, tenant query filter'ına şu exactness predicate'ini ekler:

TenantId = @tenant
AND LEN(TenantId + N'x') = LEN(@tenant + N'x')

Suffix, trailing space'leri internal hale getirir; böylece LEN onları sayar. Bu yöntem nvarchar için parametre byte uzunluğuna bağımlı değildir. Equality predicate'i korunduğu için SQL Server composite index üzerinde Index Seek + Filter kullanılabilir.

Exactness ve production verifier birlikte, tek API ile etkinleştirilmelidir:

optionsBuilder
    .UseSqlServer(connectionString)
    .UseMecesoftSqlServerTenancy();

UseMecesoftSqlServerTenancy() production collation verifier’ı ve exact tenant filter augmenter’ını birlikte kurar. String tenant mapping varken bu yapılandırma eksikse model/startup doğrulaması fail-closed olur. Production verifier yalnızca built-in SqlServerTenantFilterExpressionAugmenter örneğini SQL Server exactness olarak kabul eder; no-op veya custom augmenter reddedilir. Eski UseMecesoftSqlServerExactTenancy() adı geriye uyumluluk için aynı güvenli yapılandırmaya yönlendirilir.

Bu extension tüm string tenant mapping'lerine uygulanır. String mapping'ler ITenantExactMapping marker'ını taşımalıdır; TenantEntityMapping<TEntity, TTenantId> bunu sağlar. Marker tek başına güvenlik kanıtı değildir: core, tenant property'nin ITenantEntity<T>.TenantId contract property'si olduğunu ve custom BuildFilter'ın doğrudan tenant property eşitliği içerdiğini ayrıca doğrular. Custom mapping marker taşımıyorsa veya filter'ı genişletmeye çalışıyorsa model oluşturma fail-closed olur. Guid tenant mapping'leri değişmez.

Exactness extension'ı olmadan SQL Server string tenant desteği Limited kalır. Raw SQL, IgnoreQueryFilters, bulk ve doğrudan DB değişiklikleri exactness'i atlar.

Startup

using var scope = services.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<AppDbContext>();
context.ValidateTenantSecurity();

String tenant kullanılıyorsa schema hazır olduktan sonra çağrılmalıdır.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 45 10/25/2026
1.0.0 47 10/25/2026

1.1.0: restores Mecesoft.Repository compatibility, standard/Identity DbContext support, general-purpose unit of work, detached concurrency helpers, and optional soft-delete/audit services.