Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Tenant FK #8739


User avatar
0
ArturCorreia created

Hi

Can you help me please I have created a table and in my table i have a (TenantId FK ID), to refernce ZERO table TenantId.

When i run power tools my build fails complaining about abiguity of this tenantId within the OnModelCreating method of the context class.

Error CS0229 Ambiguity between 'LeaveType.TenantId' and 'LeaveType.TenantId' EZNow.EntityFrameworkCore

modelBuilder.Entity<LeaveType>(l => { l.HasIndex(e => new { e.TenantId }); });

Any Ideas?

Thanks.


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you share your Entity class as well ?

    Thanks.

  • User Avatar
    0
    ArturCorreia created

    Hi ismcagdadm the entity was just the same as our table, I power tooled that table to entity. (But now deleted the entity as going to start power tools again once I know the answer to below)

    From the email conversation...

    We’re setting up a bunch of tables and the objective is to have a full DB schema designed in advance and then use PowerTools to build some basic pages, and then more complex pages that need to read/write from multiple tables too.

    One of the columns I’m trying to add to our DB schema is the TenantID column with a foreign key to AbpTenants. But Powertools fails… For a multi-tenant solution, is the Zero solution managing the records per TenantID automatically? Can you point me in the direct direction on this one please?

    Should I be using a tenantId in my new tables or rely on tenantId built into zero?

    Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ArturCorreia

    If you only use TenantId in your tables, it will not work in AspNet Zero. At least it is not enouhg. Your entity on the server side must implement IMayHaveTenant or IMustTenant interface.

    If you want to first create your tables and then generate entities using Power Tools, you can add IMayHaveTenant interface to your entities.

  • User Avatar
    0
    ArturCorreia created

    Hi ismcagdas

    OK, good to know.

    I will remove tenant from my table/s and do it that way then.

    Thanks.