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 3998538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:32:16+00:00 2026-05-20T07:32:16+00:00

I have just started using EF Code First to implement a simple blog. I

  • 0

I have just started using EF Code First to implement a simple blog.

I have a Post object which has a product variable

virtual Product Product { get; set; }

The Product class has a collection of categories

virtual ICollection<Category> Categories { get; set; }

Finally the category has a collection Posts.

virtual ICollection<Post> Posts { get; set; }

This so far has worked well. Now I want to get posts for a particular category. I was originally doing this in my PostRepository by passing in a category Id : such as

public IQueryable<Post> GetPosts(int catId) {
    var q = _db.Posts.Select(p => p).Distinct();
    if (catId > 0)
        q = q.Where(p => p.Product.Categories.Any(c => c.ID == catId));
}

This works great, however I also use a CategoryRepository to get my category. Since the category has a list of products, which in turn has a list of posts, I thought it would be better to just use that, and remove the category from my PostRepository.

However, I have run into an issue. To get the posts, I use this in my controller:

model.Category = _cr.GetCategory(catId);
model.Posts =
    new PaginatedList<Post>(model.Category.Products.Select(p => p.Posts)
               .AsQueryable(), pageNumber, _defaultPageSize);

The PaginatedList is the one from NerdDinner taking in an IQueryable. Now, this errors because I am passing in a

IQueryable<ICollection<Post>>

So my question is how can I get a IQueryable from my Category entity? I’m sure the answer is simple, but I’ve been trying all kinds of combinations to no avail.

  • 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-05-20T07:32:17+00:00Added an answer on May 20, 2026 at 7:32 am

    Did you try .SelectMany(p => p.Posts).AsQueryable()?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started using Google Chrome , and noticed in parts of our site,
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
I just started using SVN, and I have a cache directory that I don't
I've just started using Java's enums in my own projects (I have to use
I’ve only just started using ASP.NET MVC, and I have a somewhat trivial question:
Just getting started using MVC in ASP.NET, I'm going to have it so users
I have been looking at using TDD and implementing proper testing (only just started
I am just getting started again with Mac development. I am using CoreMIDI which

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.