-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark entities as MultiTenant without using an Attribute #184
Comments
Oops, public static void EnforceTenantId(TenantInfo tenantInfo,
ChangeTracker changeTracker,
TenantNotSetMode tenantNotSetMode,
TenantMismatchMode tenantMismatchMode)
{
var changedMultiTenantEntities = changeTracker.Entries().
Where(e => e.State == EntityState.Added || e.State == EntityState.Modified || e.State == EntityState.Deleted).
Where(e => Shared.IsMultiTenant(e.Metadata));
// ... rest of method |
I had the same thought about using the model builder as I started looking into IdentityServer support. I think this adds a lot of value as well. If you start a PR that would be great, otherwise maybe I can get you to review mine? Not sure when I will get to it--a few other items on the plate as well. |
Ok, I'll look into putting together a PR. I likely won't be able to get to it until the weekend or maybe even next week. |
hi @GordonBlahut, I just submitted PR #191 Thoughts? |
No joke I was just about to start my implementation. I will take a look at the PR. |
If entity classes are in a class library (e.g. MyApp.Core) and the EF configuration in another class library (e.g. MyApp.Data), the MyApp.Core class library has to take on Finbuckle.MultiTenant.EntityFrameworkCore (and therefore EntityFrameworkCore itself) in order to use
[MultiTenant]
on classes.A solution to mark entities as
MultiTenant
without an attribute would be great. It would make a lot of sense (to me anyway) to make this part of model building API. Maybe an extension method onEntityTypeBuilder
andEntityTypeBuilder<T>
so you could domodelBuilder.Entity<MyEntity>().HasMultiTenant()
.That way the
MyApp.Core
library doesn't need to depend on Finbuckle at all.For example, the
HasMultiTenant
extension method could add an annotation or something to the entity type:Shared could add
Shared.IsMultiTenant
and look for the annotation instead of the attribute:(or since it's a static method anyway, it could be an extension method of
IEntityType
).MultiTenantDbContext.MultiTenantEntityTypes
andMultiTenantIdentityDbContext.MultiTenantEntityTypes
would callShared.IsMultiTenant
instead ofShared.HasMultiTenantAttribute
to build the list ofMultiTenant
entity types.MultiTenantIdentityDbContext.OnModelCreating
would also have to callShared.IsMultiTenant
when modifying indexes on identity tables.MultiTenantAttribute
could remain as well for backwards compatibility and for those who prefer attribtues to annotate models.Shared.SetupModel
would simply get a list of entities with the attribute and callHasMultiTenant
on them to add the annotation and then loop through entity types with the annotation instead:That way both the fluent model builder API as well as the attribute could be used to mark entities as
MultiTenant
.Caveat:
MultiTenantDbContext.MultiTenantEntityTypes
andMultiTenantIdentityDbContext.MultiTenantEntityTypes
would not be able to return a list of results until afterOnModelCreating
is called but I'm not sure how much that would end up being an issue.Let me know if you're interested in this concept. Maybe I could put together a PR but I don't currently have .NET Core 3.0.
The text was updated successfully, but these errors were encountered: