Hi Guys,
Thanks heaps for your help so far, Here is the code for the GetUserById. I dont want to add roles in to the collection for deletion, Becuase I dont actually want to delete the role, Just the user and the link between the user and the role.
/// <summary>
/// Get UserEntity By User Id.
/// </summary>
/// <param name="userId">The Id of the userEntity to fetch.</param>
/// <returns>A <see cref="UserEntity"/> instance.</returns>
public static UserEntity GetUserById(int userId)
{
UserEntity entity = new UserEntity(userId);
using (IDataAccessAdapter dataAdapter = new DataAccessAdapter())
{
// Prefetch the users roles.
IPrefetchPath2 Path = new PrefetchPath2((int)EntityType.UserEntity);
Path.Add(UserEntity.PrefetchPathRoles);
Path.Add(UserEntity.PrefetchPathCustomers);
// Fetch The Entity
dataAdapter.FetchEntity(entity, Path);
}
return entity;
}
When it goes to delete the collection the users roles collection has 1 item in it userEntity.Roles[0].Name = "Client" so it is connected and the data is there. Looking at the database shows there is a new user record, a new userrole record and a role entity all connected together.
Hmm should I be deleting the RolesEntity rather than the UserRoleEntity Connection?
Thanks
M