Skip to content
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

How to add tenancy to inherited models #17

Open
pwfraley opened this issue Mar 24, 2021 · 0 comments
Open

How to add tenancy to inherited models #17

pwfraley opened this issue Mar 24, 2021 · 0 comments

Comments

@pwfraley
Copy link

pwfraley commented Mar 24, 2021

I am having a problem I can't seem to solve (I am by no way a c# expert)

I have a abstract base entity called BaseContact
From this BaseContact I inherit PhoneContact and EmailContact.

If I try to add the Tenancy to PhoneContact and EmailContact I get the error that filters can only be added to the BaseEntity. But if I only add the Tenancy to the BaseEntity my application crashes trying to add a Phone- or a EmailContact with the message tenantId can not be null.

How do I go about adding tenancy to inherited models?

This Compiles, but crashes upon Creation of inheritated models:

            modelBuilder.Entity<BaseContact>(
                ctx =>
                {
                    ctx.ToTable("Contact");
                    ctx.HasIndex(ct => ct.Id);
                    ctx.HasTenancy(() => _tenancyContext.Tenant.Id, _tenancyModelState, hasIndex: true);
                    ctx.HasQueryFilter(ct => ct.TenantId == _tenancyContext.Tenant.Id);
                }
            );

            modelBuilder.Entity<PhoneContact>().HasBaseType("BaseContact");
            modelBuilder.Entity<EmailContact>().HasBaseType("BaseContact");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant