Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:08:47+00:00 2026-06-07T11:08:47+00:00

I have these classes public class CoffeeUser { public CoffeeUser() { DrinkedCoffees = new

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:08:49+00:00Added an answer on June 7, 2026 at 11:08 am

    How about

      var DrinkedCoffies = ctx.CoffeeUsers.SelectMany(u => u.DrinkedCoffees, (u, cof) => new { FirstName = u.FirstName, LastName = u.LastName, DateDrinked = cof.DateDrinked } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these classes: public class Person { public int Id{ get; set ;}
I have these classes: public class RegionResult { public string Region { get; set;
I have these classes: public class MovieExt { public string Title { get; set;
I have two classes: public class TestClass1 { public int TestInt { get; set;
I have these classes: public abstract class CustomField { public String Id { get;
I have this classes: public class User { [Key] public Guid UserId { get;
Say you have these two classes. public class Author { public int ID {get;
Say I have these classes: public class Loan { @Id private Long id; @ManyToOne
I have these classes: public class AllegationContent { @DatabaseField(generatedId = true) protected long id;
Concerning data binding I have these classes: public class Foo : List<Bar> { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.