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

  • SEARCH
  • Home
  • 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 6119731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:35:13+00:00 2026-05-23T15:35:13+00:00

I use c#, linq and EF4. I have two tables in my DataBase represented

  • 0

I use c#, linq and EF4.

I have two tables in my DataBase represented in my Conceptual Model:

DataBase Tables:

CmsContents
CmsRelatedContents (Junction table)

Entity Type:

CmsContent

I have some Navigational Properties:

for CmsContent --> CmsContents --> Return Collection of CmsContent --> from role: CmsContent1 to CmsContent (map ToContentId)
for CmsContent --> CmsContents1 --> Return Collection of CmsContent --> from role: CmsContent to CmsContent1 (map FromContentId)

Data in DataBase for the Junction Table (CmsRelatedContents) is presented:

FromContentId   ToContentId
4               3
5               2

In table CmsContents:

ContentId
2
3
4
5

I need use Linq or EF to retrieve Objects in CmsContent associated in the ToContentId column filtering the Junction table for a specific FromContentId

Do you have an idea how to do it?

Please provide me sample of code. Thanks for your help on this!


EDIT : SOLUTION

// Option A:
           var test = from cnt in context.CmsContents
                       where cnt.CmsContents.Any(t => t.ContentId == contentId)
                       select cnt;

// Option B: 
       var toContents = context.CmsContents.Where(r => r.CmsContents.Any(t => t.ContentId == contentId));

Thanks guys from your support!

  • 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-23T15:35:14+00:00Added an answer on May 23, 2026 at 3:35 pm

    Not sure if i understood you correctly but this might be what you need:

    dbContext.CmsContent.Where(r => r.CmsContents.Any(t => t.Id = someId))

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

Sidebar

Related Questions

I use c#, linq and EF4. I have two tables in my DataBase represented
I use c#, linq and EF4. I have two tables in my DataBase represented
While trying to use LINQ to SQL I encountered several problems. I have table
I use LINQ, C#, EF4. I have this query expression in Linq. I need
I use C#, Linq and EF4. I have a front end for my website,
I use c# asp-net 4 and ef4. I have a LINQ query which create
I use Linq-to-SQL which will generate classes for database tables dragged to its designer.
I use LINQ-SQL as my DAL, I then have a project called DB which
Is it possible to use precompiled linq queries with repositories. Current I have my
I use asp.net 4 c# and ef4. I have this code, it should compile

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.