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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:51:03+00:00 2026-05-20T03:51:03+00:00

I am trying to get to grips with EF4 CTP5. I have two classes

  • 0

I am trying to get to grips with EF4 CTP5. I have two classes that have a many-to-many relationship: Member and MemberGroup. CTP5 Code First generated two tables (Members and MemberGroups) and also a third named MemberGroupMembers that has two columns (MemberGroupId and MemberId) So far everything is as I was expecting it to be. I have seeded the database with some Members and MemberGroups. The problem is that I cannot find how to assign one or more MemberGroups to a Member, which would result in inserting a row into the MemberGroupMembers table for each MemberGroup that the Member is assigned to.

    public class Member
{
    public int Id { get; set; }

    public Guid SecureId { get; set; }

    public DateTime JoinedOn { get; set; }

    public virtual ICollection<MemberGroup> MemberGroups { get; set; }
}

public class MemberGroup
{
    public int Id { get; set; }

    public string Name { get; set; }

    public DateTime CreatedOn { get; set; }

    public virtual ICollection<Member> Members { get; set; }
}

public class CTP5testContext : DbContext
{
    public CTP5testContext() : base("CTP5test") { }

    public DbSet<Member> Members { get; set; }

    public DbSet<MemberGroup> MemberGroups { get; set; }
}

public class CTP5testContextInitializer : DropCreateDatabaseIfModelChanges<CTP5testContext>
{
    protected override void Seed(CTP5testContext context)
    {
        new List<Member>
        {
            new Member
            {
                Id = 1,
                SecureId = Guid.NewGuid(),
                JoinedOn = DateTime.Now
            }
            ,
            new Member
            {
                Id = 2,
                SecureId = Guid.NewGuid(),
                JoinedOn = DateTime.Now
            }
        }.ForEach(m => context.Members.Add(m));

        var memberGroup = new MemberGroup()
        {
            Id = 1,
            Name = "MemberGroup 1",
            CreatedOn = DateTime.Now
        };

        context.MemberGroups.Add(memberGroup);

        // How can I assign Member 1 to MemberGroup 1 ?????

        context.SaveChanges();
    }
}

I hope that it is clear what I am trying to do here and that someone can give me an example of how to achieve this.

Regards,
Erwin

  • 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-20T03:51:03+00:00Added an answer on May 20, 2026 at 3:51 am

    You must use collections defined in your POCO classes. So if you want to assign member1 to memberGroup you will simply call:

    memberGroup.Members.Add(member1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to get to grips with the code of a system that has been
I'm trying to get to grips with Qt's signal and slots mechanism. I have
I'm trying to get to grips with regular expressions: I have a database connection
I am trying to get to grips with programmatically configuring views. I have a
Trying to get the grips of best URI practice in RESTfulness... Let's say that
I have been trying to get to grips with Hibernate's inverse attribute, and it
I'm learning Java here and trying to get to grips with classes and how
I am trying to get to grips with Jackson JSON parser and have found
I am trying to get to grips with MS Dynamics CRM 2011. I have
I'm trying to get the grips of using prototypal inheritance. Here is the code

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.