Replies: 2 comments 21 replies
-
So for having the same result as your example there is two way: example code : var list = new List<Class1>()
{
new()
{
State = "ok",
Childs = new List<Class2>()
{
new()
{
State = "ok",
UserId = 1,
},
new()
{
State = "error",
UserId = 2,
}, new()
{
State = "error",
UserId = 3,
},
new()
{
State = "error",
UserId = 4,
}
}
},
new()
{
State = "error",
Childs = new List<Class2>()
{
new()
{
State = "ok",
UserId = 4,
},
new()
{
State = "error",
UserId =1,
}, new()
{
State = "error",
UserId = 6,
},
new()
{
State = "error",
UserId = 1,
}
}
}
}.AsQueryable();
//How to convert to Gridify
var get = list.Where(a => a.Childs.Any(x => x.UserId == 1 && x.State == a.State));
internal class Class1
{
public string State { get; set; }
public List<Class2> Childs { get; set; }
}
internal class Class2
{
public string State { get; set; }
public int UserId { get; set; }
} First, if you want to always map your child State to the parent state you should not use gridify because it is a static hard-coded query: e.g using query builder var qb = new QueryBuilder<Class1>()
.AddMap("child_id", q => q.Childs.Select(c => c.UserId))
.AddCondition("child_id = 1") // this is your dynamic part
.Build(list);
// combine your static part
qb = qb.Where(q => q.Childs.Any(c => c.State == q.State));
var result = qb.ToList(); The second way, if you wanna Control the state: // get the state from user to control the filtering
var state = "error";
var qb = new QueryBuilder<Class1>()
.AddMap("child_id", q => q.Childs.Select(c => c.UserId))
.AddMap("state", q => q.State)
.AddMap("child_state", q => q.Childs.Select(c => c.State))
.AddCondition($"child_id = 1, child_state={state}, state={state}")
.Build(list);
var result = qb.ToList(); |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As in the picture, I need to query x3.state == a.state,
Beta Was this translation helpful? Give feedback.
All reactions