public UserProfile Save(UserProfile entity)
        {
            using (Dbml.DataClassesDataContext db = new Dbml.DataClassesDataContext(this.ConnectionString))
            {
                Dbml.UserProfile dbItem = db.UserProfiles.Where(x => x.Id == entity.Id).SingleOrDefault();
                bool isNew = false;
                if (dbItem == null)
                {
                    dbItem = new Dbml.UserProfile();
                    isNew = true;
                }
                else
                {
                    //remove them for refresh
                    //wish there was a better way to do this but...
                    db.Application_UserProfiles.DeleteAllOnSubmit
                    (
                        db.Application_UserProfiles.Where(x => x.UserProfileId ==  entity.Id)
                    );
                }
                foreach( Ent.Application a in entity.Applications)
                {
                    Dbml.Application_UserProfile dbAppUser = new Dbml.Application_UserProfile();
                    dbAppUser.UserProfileId = entity.Id;
                    dbAppUser.ApplicationId = a.Id;
                    dbItem.Application_UserProfiles.Add(dbAppUser);
                }
                dbItem.Name = entity.Name;
                dbItem.Email = entity.Email;
                dbItem.LastSignInDate = entity.LastSignInDate;
                dbItem.OpenIdId = entity.OpenIdId;
                dbItem.RegisterDate = entity.RegisterDate;
                dbItem.UserName = entity.UserName;
                dbItem.ModifiedBy = entity.ModifiedBy;
                dbItem.ModifiedDate = entity.ModifiedDate;
                dbItem.CreatedDate = entity.CreatedDate;
                dbItem.CreatedBy = entity.CreatedBy;

                if (isNew)
                {
                    db.UserProfiles.InsertOnSubmit(dbItem);
                }
                db.SubmitChanges();

                entity.Id = dbItem.Id;
                return entity;
            }
        }
 partial void UpdateUserProfile(UserProfile instance);
 partial void DeleteUserProfile(UserProfile instance);
 partial void InsertUserProfile(UserProfile instance);