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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:07:31+00:00 2026-05-26T19:07:31+00:00

I Have a Phone Book With a Share table and a Member table The

  • 0

I Have a Phone Book With a Share table and a Member table The share table must have 2 FK to Member table one as a owner and another as a Joint Member but I can not Model it truly:

This is My DB Model:

public class PhoneBookDB : DbContext {

    public DbSet<Member> Members { get; set; }
    public DbSet<ContactKind> ContactKinds { get; set; }
    public DbSet<Contact> Contacts { get; set; }
    public DbSet<NumberKind> NumberKinds { get; set; }
    public DbSet<Number> Numbers { get; set; }
    public DbSet<AddressKind> AddressKinds { get; set; }
    public DbSet<Address> Addresses { get; set; }
    public DbSet<City> Cities { get; set; }
    public DbSet<Group> Groups { get; set; }
    public DbSet<ShareAccess> ShareAccesses { get; set; }
    public DbSet<Share> Shares { get; set; }

}

This is the Model of Share:

public class Share {

    public long Id { get; set; }
    public Group Group { get; set; }
    public ShareAccess ShareAccess { get; set; }
    public Member Owner { get; set; }
    public Member JointMember { get; set; }

}

And This is the Model of Member:

public class Member {

    public long Id { get; set; }
    public string UserName { get; set; }
    public virtual ICollection<Group> Groups { get; set; }
    public virtual ICollection<Share> OwnerShares { get; set; }
    public virtual ICollection<Share> JointShares { get; set; }
    public virtual ICollection<NumberKind> NumberKinds { get; set; }
    public virtual ICollection<AddressKind> AddressKinds { get; set; }
}

with this design of models I have 4 FK in share table to member table at DB, And Also I cant Access to share elements by Member Model

Like this:

db.Members.Single(m => m.Shares.Any(sh => sh.Id == item.Id))

or this one:

db.Shares.Single(sh => sh.Id == item.Id).JointMember

but both of them return Null.

I try more version of models like: one ICollection in Member or one Member prop in Share Model but none of them give me a true DB tables and answer.
Also I need atleast one Collection of share in Member Model for retrieve shares element by member, as you know I coded by EFCodeFirst And I need a way to solve this problem, Thank you

  • 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-26T19:07:31+00:00Added an answer on May 26, 2026 at 7:07 pm

    You need o define he relaionships in OnModelCreating event of your DbContext like this,

        modelBuilder.Entity<Share>().
    HasRequired(s=>s.Owner ).WithMany(p=>p.OwnerShares).WillCascadeOnDelete(false);
    
        modelBuilder.Entity<Share>().HasRequired(s=>s.JointMember )
    .WithMany(p=>p.JointShares );
    

    I think in the same way you may be need to define other relationships(ShareAccess ,Group) also. Here is a good tutorial to start with,
    http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx

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

Sidebar

Related Questions

I have the following scenario: 1) A phone book table 2) Multiple ways of
I have a phone-book program written in C++, that uses the MVC model, now
I want to make address book application in android which can have Name,phone No,
I'm trying to create an address book application with one table for People, another
I'm writing a Phone Book application. I have a listview in which you can
I have an application ( Amnesia ) which lets you create memos/stickers/alarms/Phone Book, and
I have a phone number field that can have lots of different characters such
If I have a phone number, and the owner of the number Has a
If I have an international phone number such as this: 0541754301 how can I
I have to work with an application in C++ similar to a phone book:

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.