Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.3k stars 265 forks source link

adjustindex api surface interaction with model class inheritance #788

Closed vigouredelaruse closed 6 months ago

vigouredelaruse commented 6 months ago

howdy- i am unable to use the adjustindex apis when the model features inheritance

tested model scenario public class RssBlog : Blog { public string RssUrl { get; set; } }

` IMutableIndex? origIndex = null;

        using var db = GetDbContext(builder =>
        {
            builder.Entity<Blog>()
                .HasIndex(e => e.BlogId, "CustomIndexName")
                .HasDatabaseName("CustomIndexDbName");

            origIndex = builder.Entity<Blog>().Metadata.GetIndexes().First();
            builder.Entity<Blog>().IsMultiTenant().AdjustIndex(origIndex);

            builder.Entity<RssBlog>()
            .HasIndex(e => e.BlogId, "RssCustomIndexName")
            .HasDatabaseName("RssCustomIndexDbName");

            var rssIndex = builder.Entity<RssBlog>().Metadata.GetIndexes().First();
            builder.Entity<RssBlog>().IsMultiTenant().AdjustIndex(rssIndex);
        });
        var index = db.Model.FindEntityType(typeof(Blog))?.GetIndexes().First();
        Assert.Equal("CustomIndexName", index!.Name);
        Assert.Equal("CustomIndexDbName", index.GetDatabaseName());`

i've tested this with the finbuckle unit tests as per this commit

perhaps i have misconfigured the indexes? image

please advise

AndrewTriesToCode commented 6 months ago

Hi, I recommend that if you have explicit control of your entities that you set the index the normal way and include your tenant column. The helper methods are limited and intended to help when you inherit a model that you can’t directly alter.

Edit: fixed typos

vigouredelaruse commented 6 months ago

thanks - i will explicitly configure the indexes to include tenantid column