我正在尝试根据用户角色过滤我的活动。只允许经理查看包含该角色的活动Manager
。请参阅下面的详细信息。
数据:
var user = new User
{
Roles = [
"Manager"
]
}
var activities = new List<Activity>
{
new Activity
{
Description = "My First Activity",
Roles = [
"Admin",
"Manager"
]
},
new Activity
{
Description = "My Second Activity",
Roles = [
"Admin"
]
},
new Activity
{
Description = "My Third Activity",
Roles = [
"Manager",
"Client"
]
},
}
过滤活动的查询
var filtered = await context.Query<Activity>()
.Where(x => x.Roles.Any(y => user.Roles.Contains(y)))
.ToListAsync();
过滤后的预期结果:
[
{
new Activity
{
Description = "My First Activity",
Roles = [
"Admin",
"Manager"
]
}
new Activity
{
Description = "My Third Activity",
Roles = [
"Manager",
"Client"
]
},
}
]
查询错误
System.InvalidOperationException : Can't extract value from expression of type: Parameter
我收到一个错误,所以很明显我做错了什么。这是正确的方法还是有更好的方法?