Base solution for your next web application
Open Closed

Accessing shared data available to all tenants #8749


User avatar
0
purplerain created

Hi,

There is a scenario where we keep some data which should be available to all tenants but in the virtual entity it's coming as null so I suppose it's to do with multi tenancy, what is the way around this.

For example

public class ClassOne : Entity, IMustHaveTenant { public virtual int TenantId { get; set; } public int ClassTwoId {get;set;} [ForeignKey("ClassTwoId")] public virtual ClassTwo {get;set;} }

public class ClassTwo : Entity { }

ClassTwo is coming as null when I access ClassOne although there is a data for the id.

How do I fix this? Plz help


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

    Hi,

    Just remove IMustHaveTenant interface from your Entity.

  • User Avatar
    0
    purplerain created

    No that's the point. ClassOne is IMustHaveTenant and ClassTwo should be accessible to all tenants.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you share your query ?

  • User Avatar
    0
    purplerain created

    var query = _classOneRepository.GetAll();

    Since GetAllIncluding is only used with collections, it should get virtual with GetAll, right?

  • User Avatar
    0
    ismcagdas created
    Support Team

    You have to include it into your query;

    var query = _classOneRepository.GetAll();
    .Include(e => e.ClassTwo);
    
  • User Avatar
    0
    purplerain created

    Ok thank you very much, it works.