I have these classes
public class CoffeeUser
{
public CoffeeUser()
{
DrinkedCoffees = new Collection<DrinkedCoffee>();
}
public long CoffeeUserID { get; set; }
public Guid Code { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EMail { get; set; }
public virtual ICollection<DrinkedCoffee> DrinkedCoffees { get; set; }
}
public class DrinkedCoffee
{
public long DrinkedCoffeeID { get; set; }
public DateTime DateDrinked { get; set; }
}
How can i query for all items of DrinkedCoffees along with FirstName and LastName?
Result should look like this:
Tyler John 27.3.2012
Tyler John 28.3.2012
Tyler John 29.3.2012
I have tryed several queries but i was unsuccessful so far.
this was closest i was able to achieve:
var list_4 = ctx.CoffeeUsers.Where(u => u.DrinkedCoffees.Count > 0).SelectMany(u => u.DrinkedCoffees).ToList();
Well, it took me 45 seconds to do this in sql. And 4 hours to not do it in entity 🙂
How about