views:

44

answers:

1

I am currently using LINQ and the Entity Framework to do my database connection layer. In my database I have a Files table and a Products table. I also have a ProductHasFiles table that joins the 2 in a many to many relationship.

My issue is this. I have a single file loaded in my context and I have a list of Product IDs that I need to either attach or detach from to the file record. How do I do that?

I know I can get all of the current Products attached to the File by doing File.Product.Load(); but how do I detach them once I do this? Also, is there a way to attach existing Products without loading the whole Product entry? I already have the ID so I hope that would be enough.

+1  A: 

If you want to add or remove object without retrieving it, use stub entities: How to delete an object without retrieving it. Create stub, add to context, add to file.Products.

Why do you want to detach after loading?

LukLed