How do I query the "one" entity of a "one-to-many" foreign key for distinct values? #4101
Unanswered
anilknarayan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the query to use to query the "one" entity in a "one-to-many" relationship. For example with a Driver and Car entities knowing that one driver can own many cars, how do I say, list all drivers that drive Toyotas, if I want to query the Driver, instead of Car. The query below returns a LINQ translation error -
query{ Driver( where: { Cars: { some: {Brand: { eq: "Toyota" } } } } ){ DriverName } }
The error I get looks like -
The LINQ expression 'DbSet<Driver>() .Where(d => new Driver{ DriverName = d.DriverName } .Cars .Any(_s1 => _s1.Brand == __p_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
The Car table has a DriverID which is the foreign key.
Beta Was this translation helpful? Give feedback.
All reactions