New Posts New Posts RSS Feed: Adding Entity via Many To Many No Payload
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Adding Entity via Many To Many No Payload

 Post Reply Post Reply
Author
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Topic: Adding Entity via Many To Many No Payload
    Posted: 13-Nov-2011 at 9:39am
I have a many to many with no payload set up. The Navigation properties show up just fine in the EDMX, and all displays correctly in the gui if I manually create the records and association record in the db.

The data setup is   Contacts --> ContactCompany <-- Company

All of this works fine until I try to add a company in code. The company entity is created and saved, but no record is created in the ContactCompany table, so the association is not created.

I downloaded and tried the ManyToMany No Payload sample. It has a function in it where it creates a new Territory and it associates it with an employee. I modified it to SaveChanges() to see if that works, but it does not seem to actually create the many to many record. It does create the Territory Entity, but the association is lost. So it appears there is a bug in this sample.

This is my code:


CompanyEntity newEntity = new CompanyEntity(this.SelectedContact.OwnedBy);
this.ContactEntityManager.AddEntity(newEntity);
this.SelectedContact.CompanyEntities.Add(newEntity);
this.ContactEntityManager.SaveChangesAsync();

Note this is NOT using codefirst, just the regular edmx.

Greg
Back to Top
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2011 at 11:15am
Note that I did get this working by using a Payload and intermediate entity and creating it manually. This works for me, so it's not an issue at this time.

Greg
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 16-Nov-2011 at 9:40am
Hi Greg;

I just tested the sample and was able to see the many-to-many records added and deleted appropriately on the mapping table. The mapping table is EmployeeTerritoryNoPayload, and not EmployeeTerritory. Could you confirm that you were looking at the right mapping table?
Back to Top
gregweb View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 10-Sep-2009
Location: Clearwater, Fl
Posts: 253
Post Options Post Options   Quote gregweb Quote  Post ReplyReply Direct Link To This Post Posted: 17-Nov-2011 at 12:51pm
Hi Denis,

I tried this again, and you are correct - it is working - I was looking at the right table, but the record was inserted at the top of the table instead of the bottom where I was looking for it. Not sure why, but no matter, it is indeed working properly.

Greg
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down