Background:
Given the following two entities joint through one to one relationship:
public partial class Parent
{
public long Id { get; set; }
public string Email { get; set; }
public virtual Details Details{ get; set; }
}
public partial class Details
{
public long Id { get; set; }
public long ParentId{ get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime Dob { get; set; }
public virtual Parent Parent { get; set;}
}
And having the following Query
model:
public class Query
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? Dob { get; set; }
}
Question
How can I apply the Query
as IQueryable
on the Parent
(or Details
) entity?
Notes based on the use case I have:
Query
class can't have two sub-classes forParent
andDetails
(it should be flattened)- DB SQL query should fetch results that matches both conditions in
Parent
andDetails
(if condition fail for details, then parent shouldn't be in the results). - There might be long list of optional fields in
Query
model. It means that the DB query should be dynamic and smart enough to know how to build the query and to know each field inQuery
belongs to which entityParent
orDetails
(i.e. I don't want a solution where I add conditions to check whetherDob
exist in theQuery
or not)
Use case:
I'm using HotChocolate framework to integrate GraphQL which uses expression trees to build the queries. The issue I'm trying to solve is mentioned here
Your support and suggestions would be highly appreciated!