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;
            }
        }
		private void detach_Application_UserProfiles(Application_UserProfile entity)
		{
			this.SendPropertyChanging();
			entity.UserProfile = null;
		}
 partial void DeleteApplication_UserProfile(Application_UserProfile instance);
 partial void UpdateApplication_UserProfile(Application_UserProfile instance);
 partial void InsertApplication_UserProfile(Application_UserProfile instance);
		private void attach_Application_UserProfiles(Application_UserProfile entity)
		{
			this.SendPropertyChanging();
			entity.Application = this;
		}