473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MVC 5 C# Entities modelBuilder with multiple tables

pod
298 100+
Hello

I am trying to get the modelBuilder.Entity to link three tables: [Committees], [Members] and [Roles]

Table [LNK_Member_Committee_Role] is where members are assigned a certain role within a certain committee; it contains the primary keys from the three tables in question.

Using the modelBuilder.Entity<Committee> code below, I am able to build entities that collects all the members assigned to a committee, and can also collect all committees a member belongs to.

But I cannot seem to be able to capture the role a member has in a committee. The options seems to make links only between two tables... I tried many ways to add the Role table to it but was unsuccessful on my own.

I did a lot of searching but to no avail. If someone can give me any insight, it would be greatly appreciated.

Thank you in advance for your replies.


Code: the model builder I have that works partially is the following:
Expand|Select|Wrap|Line Numbers
  1.     modelBuilder.Entity<Committee>()
  2.         .HasMany(e => e.Members)
  3.         .WithMany(e => e.Committees)
  4.         .Map(m => m.ToTable("LNK_Member_Committee_Role")
  5.         .MapLeftKey("CommitteeId")
  6.         .MapRightKey("MemberId"));
  7.  
  8.     public partial class LNK_Member_Committee_Role
  9.     {
  10.         public int Id { get; set; }
  11.         public int MemberId { get; set; }
  12.         public int CommitteeId { get; set; }
  13.         public int RoleId { get; set; }
  14.     }
  15.  
  16.  
  17.     public partial class Committee
  18.     {
  19.         public Committee()
  20.         {
  21.             Members = new HashSet<Member>();
  22.             Roles = new HashSet<Role>();
  23.             ChildCommittees = new HashSet<Committee>();
  24.         }
  25.         public int Id { get; set; }
  26.         public int? ParentCommitteeId { get; set; }
  27.         public string DescriptionE { get; set; }
  28.         public string DescriptionF { get; set; }
  29.         public string Abbreviation { get; set; }
  30.  
  31.         public virtual ICollection<Role> Roles { get; set; }
  32.         public virtual ICollection<Member> Members { get; set; }
  33.         public virtual Committee ParentCommittee { get; set; }
  34.         public virtual ICollection<Committee> ChildCommittees { get; set; }
  35.     }
  36.  
  37.     public partial class Member
  38.     {
  39.         public Member()
  40.         {
  41.             Committees = new HashSet<Committee>();
  42.             Roles = new HashSet<Role>();
  43.             Member_Items = new HashSet<Member_Item>();
  44.         }
  45.         [Key]
  46.         public int Id { get; set; }
  47.         public int? DistrictId { get; set; }
  48.         public int LanguageId { get; set; }
  49.         public int TitleId { get; set; }
  50.         public int PartyId { get; set; }
  51.         public int GenderId { get; set; }
  52.         public string Given { get; set; }        
  53.         public string Family { get; set; }
  54.         public string Image_Path { get; set; }
  55.  
  56.         public virtual Language Language { get; set; }
  57.         public virtual Title Title { get; set; }
  58.         public virtual Party Party { get; set; }
  59.         public virtual District District { get; set; }
  60.         public virtual Gender Gender { get; set; }
  61.  
  62.         public virtual Role Role { get; set; }
  63.         public virtual Committee Committee { get; set; }
  64.  
  65.         public virtual ICollection<Member_Item> Member_Items { get; set; }
  66.         public virtual ICollection<Committee> Committees { get; set; }
  67.         public virtual ICollection<Role> Roles { get; set; }
  68.     }
  69.  
  70.     public partial class Role
  71.     {
  72.         public Role()
  73.         {
  74.             Committees = new HashSet<Committee>();
  75.             Members = new HashSet<Member>();
  76.         }
  77.         [Key]
  78.         public int Id { get; set; }
  79.         public string DescriptionE { get; set; }
  80.         public string DescriptionF { get; set; }
  81.  
  82.         public virtual ICollection<Committee> Committees { get; set; }
  83.         public virtual ICollection<Member> Members { get; set; }
  84.  
  85.         public virtual Member Member { get; set; }
  86.         public virtual Committee Committee { get; set; }
  87.     }
  88.  
Mar 23 '17 #1
0 1171

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: E Arredondo | last post by:
Hi, I am about migrate from an old program database to MySql (Running under RH LINUX)and I'm wondering which is the best option to do : I currently have one file for each of my modules, (I'm...
1
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here...
1
by: Justin | last post by:
What is the best/easiest way to update multiple tables at a time? Can you recommend any tutorials? Thanks, Justin.
8
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables...
5
by: mimo | last post by:
Hello, I have seen samples on how to pull data from one table and save back to it using the Form View control. How do I pull from multiple tables and save back to multiple tables on one...
6
by: ApexData | last post by:
I have 2 tables: Table1 and Table2. Neither one has a primary key because each table will only have 1-record. My form is a SingleForm unbound with tabs (my desire here). Using this form, in...
0
by: redpears007 | last post by:
Morning all! :) I have a database with multiple linked tables. I have created a search form with one txt box, for entering search criteria, and a listbox for each of the tables to isplay the...
2
by: mvsmsh | last post by:
Hi , all We have hundreds of tables in on tablespace , but I'm planning to change as one table per one tablespace. . I wonder how other shops does ? Are there any special reasons in UDB...
0
by: shivapadma | last post by:
i want to know how multiple tables are added to the MS word document using vb.net i wrote following code to insert one table in MS word document using vb.net 1.opened MS word document 2.inserted...
4
Claus Mygind
by: Claus Mygind | last post by:
I am wondering what is the best solution to this problem. The platform PHP 5.3 MySQL 5.0.27 MyISAM table engine Windows xP I have a reference key in multiple tables which links those...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.