Monday, 9 September 2013

Update dependend entries in Entity Framework 5

Update dependend entries in Entity Framework 5

I'm using EF5 with a SQL Server CE for a private project and I'm trying to
update related records.
Two of my tables are:
Document 1-n DocumentFile
Documment: - Id (1)
DocumentFile - DocumentId (n) - Name
Now my question: I want to update the complete dependend List
(DocumentFile) of one document-entry. f.e. - a document (id 20) has 5
dependend entries in the DocumentFile-Table. - the user removes 3 of the
files and adds 1 more.
The result should be: 3 dependend entries (5-3+1) in the DocumentFile-table.
I tried to just remove the Collection and add the new entries, but EF will
not delete the old ones automatically. It just adds the new list to the
table.
Do i really need to delete every single dependend documentfile-entry and
add the new collection?
thanks

No comments:

Post a Comment