[英]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. 似乎有很多方法可以实现这一目标,但是我试图弄清楚.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.
当要求仅适用于索引页面时,最好对索引页面进行特定查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.