简体   繁体   中英

EF Core 2.0 - Filtering data by user best practice

There seem to be many ways to achieve this, but im trying to figure out what the best practice would be with .net Core 2 / EF core 2.0.

I have objects such as

public class Company {
    public Guid CompanyID {get; set;}
    public ICollection<Order> Orders {get; set;}
    ...
    public ICollection<UserLocation> UserLocations { get; set; }
}

public class Order {
    public Guid CompanyID { get; set; }
    public Company Company { get; set; }
    public DateTime OrderDate {get; set;}
}

public class UserLocation {
    public Guid CompanyID { get; set; }
    public Company Company { get; set; }

    public String UserId { get; set; }
    public ApplicationUser ApplicationUser { get; set; }
}

For my company Index page I only want companies that the user has access to to be displayed. Could a global filter be used for this or does that not work for this situation?

Thank you

It depends, if the user should not have access to the companies a global filter is a good solution. When the requirement only applies to the index page, you can best make a specific query for the index page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM