I have the following model
Deal.cs
public Guid Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public double? Price { get; set; }
public Guid UserId { get; set; }
public User User { get; set; }
User.cs
public Guid Id { get; set; }
public string Name { get; set; }
public string ResumptionCookie { get; set; }
public List<Deal> Deals { get; set; }
I'm trying to get all users who currently have a deal with a specific code. I could do a get all users and write a big LINQ query but there must a more elegant way.
I read the documentation but it's not quite what I'm looking for and I haven't been able to figure it out.
db.Users.Where(x=>x.Deals.Any(y=>y.Code == "your_givenCode"));
– Akash KC Mar 7 '17 at 4:57.Include
or.Collections
. I'm probably over optimizing here, but I'd like to avoid loading all the data in memory and filtering it aftewards. – martinni39 Mar 7 '17 at 5:11Deal
for this query. Akash's query does exactly what you prescribe. – Gert Arnold Mar 7 '17 at 16:15