Base solution for your next web application
Open Closed

GetAllIncluding() with Host user returns null #6872


User avatar
0
eltargrim created

I have an entity that looks something like:

 [Table("AppFoos")]
    public class Foos : FullAuditedEntity, IMustHaveTenant
    {   
        public virtual int TenantId { get; set; }
        
        [ForeignKey("CreatorUserId")]
        public User User { get; set; }
    }

Other properties omitted for brevity.

And I'm retrieving data from the associated repository using a linq query like:

return _fooRepository.GetAllIncluding(c => c.User).ToList()

This works fine if the user retreving the data is a member of a tenant but the "included" User object is null for the host user. I thought that the MustHaveTenant requirement did not apply to host users and they could fetch all data (the documentation seems to support this based on my interpretation). Why is the Include for 'User' returning null for host users and how can I fix it so that it doesn't?

Thanks in advance


2 Answer(s)
  • User Avatar
    1
    aaron created
    Support Team

    User is IMayHaveTenant.

    When is IMayHaveTenant enabled?

    IMayHaveTenant is always enabled unless you explicitly disable it.

    • https://aspnetboilerplate.com/Pages/Documents/Data-Filters#when-is-imayhavetenant-enabled-
    • https://aspnetboilerplate.com/Pages/Documents/Data-Filters#disable-filters
  • User Avatar
    0
    eltargrim created

    Thank you for the quick response! I wasn't even thinking about the interface of the included object, I was solely focused on my entity and it having 'IMustHaveTenant'. Makes total sense and works great now.