Categories
c# entity-framework linq linq-to-entities sql

LINQ subselect in table with composite key

I have a settings table in a database that is accessed through Entity Framework queries.
The settings have a composite key: Category, Group, Name, Target, Modified.
The settings obviously also contain non-key fields like value.

How would I write a query that gives me the latest setting within the same (Category, Group, Name, Target)?

More specific, I want all the latest setting entities, including the non-key fields, that matches a specific category, group, target combination.

For example: Give me all the latest settings for all targets where Category is “Database” and Group is “Timeout”.

This could be done in two-steps with an initial query returning all [Category, Group, Name, Target, Modified] keys matching the criteria and then a loop querying a setting for each key, but that would produce a lot of database queries, creating overhead.

How would I do this with LINQ if I want to minimize the number of SQL database queries executed by the framework?