The code I have put together achieves what I want, but I don't know if it is the right way to go about tackling the problem.
I am dealing with 2 tables (CLIENT, CLIENTTYPE) each of which I have an auto-generated entity for in my models folder. As I don't actually want to send all the data from each entity back to the user, I have created a viewmodel for each in a ViewModels folder.
A CLIENT can have multiple CLIENTTYPE, so I have created the a List property of ClientTypeViewModels in my ClientViewModel
public ClientsWithTypesViewModel getClientAndTypesByCode(string code)
{
var x =
from c in _context.Cases
where c.ClientID == code
select new ClientsWithTypesViewModel
{
ClientID = c.ClientID,
Title = c.Title,
Name = c.FullName,
ClientTypes = (from w in _context.ClientTypes where w.ClientType == c.ClientType select new ClientTypeViewModel { ClientType = w.ClientType, Description = w.Description }).ToList()
};
return x.FirstOrDefault();
}