I have a table Person with firstname, last name, id. Another table with roles(string) for that person, another table with categories(string). these roles and categories are connected with Occupation table (it consists of relation between roles and categories with their foreign key reference), base table PersonOccupation consists of relation between Person and Occupation table
i need to search whether firstname or last name or roles or categories consist of a letter :"A", the resultant should be
{
"Res": [
{
"PersonId": "1",
"LastName": "Chris",
"FirstName": "Angel",
"Categories": [
"HumanResource",
"It professional"
],
"Roles": [
"Manager",
"Social Activist"
]
},
{
"PersonId": "2",
"LastName": "Tex",
"FirstName": "Roy",
"Categories": [
"HumanResource",
"It professional"
],
"Roles": [
"Manager",
"Social Activist"
]
}
]
}
The LINQ I used is
Context.PersonOccupation
.Include(x => x.Occupation)
.ThenInclude(x => x.categories)
.Include(x => x.Occupation)
.ThenInclude(x => x.roles)
.Include(x => x.Person)
.AsNoTracking();
What i get is
{
"Res": [
{
"PersonId": "1",
"LastName": "Chris",
"FirstName": "Angel",
"Categories": "HumanResource"
},
{
"PersonId": "1",
"LastName": "Chris",
"FirstName": "Angel",
"Categories": "It professional"
},
{
"PersonId": "1",
"LastName": "Chris",
"FirstName": "Angel",
"Roles": "Manager"
},
{
"PersonId": "1",
"LastName": "Chris",
"FirstName": "Angel",
"Roles": "Social Activist"
}
]
}
if I understand correctly, your three classes should be:
and your code, without thinking too much, could be:
being the final result put in searchPersons.