tags:

views:

53

answers:

1

I am having creating a new record that will be inserted into the DB. I looked at the db.log but nothing gets printed. I have primary keys marked, but not sure what else needs to be done.

Have a many-to-many relationship between two tables (Member and RecForms). This is being down through a middle table of MemberRecForms that contains the ID for the other tables. In the MemberRecForm table the two keys are marked as compound primiary keys (it is also this way in the dbml).

          DataContext db = new DataContext();

          MemberRecForm r = new MemberRecForm();

          r.RecFormID = 2;

          this.MemberRecForms.Add(r);

          try
          {
            db.SubmitChanges(ConflictMode.ContinueOnConflict);
          }
          catch (ChangeConflictException)
          {
            db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
          }

When I look at r after I do this.MemberRecForms.Add(r) I see that r was updated with the correct memberID.

+1  A: 

Change "this.MemberRecForms.Add(r);" to "db.MemberRecForms.InsertOnSubmit(r);". Otherwise the datacontext will not have a reference to it, and will not insert it...

KristoferA - Huagati.com
did the above change and added r.memberID = this.memberID. Thanks
Stephen B. Burris Jr.