I was trying to operate on a collection of entities using DeleteMulti()
Dim user As New UserEntity(Me.UserId)
' clear the current assignments from the database for teh selected st body
Dim filter As New PredicateExpression(ChapterFields.StandardsBodyId = CInt(Me.c_stbody.SelectedValue))
Dim relations As New RelationCollection()
relations.Add(UserDisallowedChapterEntity.Relations.ChapterEntityUsingDisallowedChapterId)
user.UserDisallowedChapter.DeleteMulti(filter, relations)
this is the query which is executed:
DELETE FROM [VSurveyDev].[dbo].[tblUserDisallowedChapter] FROM ( [VSurveyDev].[dbo].[stjcahochapter] INNER JOIN [VSurveyDev].[dbo].[tblUserDisallowedChapter] ON [VSurveyDev].[dbo].[stjcahochapter].[id]=[VSurveyDev].[dbo].[tblUserDisallowedChapter].[DisallowedChapterId]) WHERE ( ( [VSurveyDev].[dbo].[stjcahochapter].[stbody_id] = @StandardsBodyId1))
Parameter: @StandardsBodyId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1
Unfortunately, this query deletes all the UserDsiallowedChapters for all users based on the stdbody_id! I would have expected it to **delete only the UserDisallowedChapters in my collection **where the Chapter.StandardBodyId matched my filter, NOT all the UserDisallowedChapters in the database where the filter got a match!!
We found that we had to add the UserId back into the filter in order to get the right result:
' clear the current assignments from the database for teh selected st body
Dim filter As New PredicateExpression(ChapterFields.StandardsBodyId = CInt(Me.c_stbody.SelectedValue))
filter.Add(UserDisallowedChapterFields.UserId = Me.UserId)
Dim relations As New RelationCollection()
relations.Add(UserDisallowedChapterEntity.Relations.ChapterEntityUsingDisallowedChapterId)
user.UserDisallowedChapter.DeleteMulti(filter, relations)
which gives us this query:
DELETE FROM [VSurveyDev].[dbo].[tblUserDisallowedChapter] FROM ( [VSurveyDev].[dbo].[stjcahochapter] INNER JOIN [VSurveyDev].[dbo].[tblUserDisallowedChapter] ON [VSurveyDev].[dbo].[stjcahochapter].[id]=[VSurveyDev].[dbo].[tblUserDisallowedChapter].[DisallowedChapterId]) WHERE ( ( [VSurveyDev].[dbo].[stjcahochapter].[stbody_id] = @StandardsBodyId1 AND [VSurveyDev].[dbo].[tblUserDisallowedChapter].[UserId] = @UserId2))
Parameter: @StandardsBodyId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
Parameter: @UserId2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 36287.
Is this the way the LLBL generated code is supposed to work? Shouldn't myEntityCollection.DeleteMulti(filter, relations) opreate only on the items in myEntityCollection, not others in the database??