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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:52:23+00:00 2026-06-16T22:52:23+00:00

I have two tables: Relationships (ID, UserID, Type, Contact ID) Contacts (ID, Name, Address)

  • 0

I have two tables:

Relationships (ID,   UserID,   Type,   Contact ID)   

Contacts (ID,   Name,  Address) 

When the type is 5 in Relationship table, Contact ID is the ID in the Contacts table.

I want to get all the contacts information for a particular user

Here is what I have :

IEnumerable<Relationship> rels  = user.Relationships.Where(r => r.Type==5)
foreach (Relationship r in rels)
{
            contact = contactRepository.Find(r.ContactID);  // Returns Contact Object 
            Relation relation = new Relation(r, contact);   
            RelationList.Add(relation);

 }

Is this correct way to do this?

I have seen other post mentioning TPC. However, I did not quite understand all that and it seemed TPC only works for code first process.

  • 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-16T22:52:24+00:00Added an answer on June 16, 2026 at 10:52 pm

    You can user followng linq statement to get the contacts of a given userID (let’s say UserID=15) by using relatonships and contacts tables:

    var contacts=from r in Relationships
                 join c in Contacts on r.ContactID equals c.ID
                 where r.Type=5 and r.UserID=15
                 select c;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framework and I have two tables, a contact relationship table
I have a many to many relationship between two existing tables (User: UserId, Name)
I have two tables connected with one to many relationship. Parent Table is a
I have two tables with primary foreign key relationship. The table in foreign key
I have two tables with a many to many relationship, through a third table.
I have two tables with a linking table describing their many-to-many relationship. TABLE buildings
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I have two tables, in which one user can have several contacts: User(UserId, UserName)
I have two tables: tblBadge ------- ID Name tblBadgeUsers ------- BadgeID UserID A user
I have two tables in my database which have a one-to-one relationship. I want

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.