I am trying to manage users and the roles they belong but I am getting this error message when I try to update their role mappings:
Collection was modified; enumeration operation may not execute.
I am using llblgen 2.0 v2.0.50727
I have the database setup like this
User table
Id,
Name
Role table
Id,
Name
UserRoles Table
UserID,
RoleID
What I do is display a list of all availiable roles to the screen as a checked list, before rendering I look at the users rolemappings(UserRoles Table Entires) and then check those. After the edit is done I call the UserEntity and clear out its RoleMappings then add back the new roles selected during the edit. Here is the code
this._sb_localEntity.RoleMappings.Clear();
this._sb_localEntity.RoleMappings.AddRange(this.ctrlUserRoles.CurrentUserRoles);
The currentUserRoles is an EntityCollection<> of RoleMappings.
The clear works but the add back gets me the error message above. Here is the stack trace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List1.Enumerator.MoveNext()
at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore
1.AddRange(ICollection`1 c)
at PetRescueCentral.Web.Controls.Users.AddEditUser.UnBind() in C:\source\PetRescueCentral\trunk\WebSite\Controls\Users\AddEditUser.ascx.cs:line 171
at PetRescueCentral.Web.Controls.Users.AddEditUser.cmdSave_Click(Object sender, ImageClickEventArgs e) in C:\source\PetRescueCentral\trunk\WebSite\Controls\Users\AddEditUser.ascx.cs:line 252
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Not sure if there is a better way to approach this, I am open to any suggestions.
Thanks,
Frank