ASP.NET SQL Profile Provider. Does the ProfileBase.Create () method use database access?

I work with SQLMemebershipProvider and using profiles. I have a custom UserProfile class that inherits from the ProfileBase class, and I use it to set custom properties such as "FullName". I want to skip all users in the database and access their profile properties. At each iteration, I call ProfileBase.Create () to get a new profile and then access the properties.

It seems to me that every time ProfileBase.Create () is called, it gets into my SQL database. But I'm just looking for confirmation of this. So, does anyone know if this really really gets into the database every time?

And even better, does anyone have a better solution, how could I make one call to the database so that all users get their custom profile attributes?

I know that I can write my own stored process, but I wonder if there is a way that is built into the Membership Provider.

+4
sql profile membership provider
source share
2 answers

Mike, I believe that what you watched is true. I am working with a ProfileProvider that uses Azure TableStorage as a data store. I wanted to get a list of user profiles from a database and combine them with information from a membership provider. It took some time until I realized that calling ProfileBase.Create () with the username as an argument searches in TableStorage and actually retrieves the data associated with that username. As far as I know, calling this Create () method is misleading, I would expect Load () or Get (). Currently my code is as follows:

public IEnumerable<AggregatedUser> GetAllAggregatedUsers() { ProfileInfoCollection allProfiles = this.GetAllUsersCore( ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All) ); //AggregatedUser is simply a custom Class that holds all the properties (Email, FirstName) that are being used var allUsers = new List<AggregatedUser>(); AggregatedUser currentUser = null; MembershipUser currentMember = null; foreach (ProfileInfo profile in allProfiles) { currentUser = null; // Fetch profile information from profile store ProfileBase webProfile = ProfileBase.Create(profile.UserName); // Fetch core information from membership store currentMember = Membership.FindUsersByName(profile.UserName)[profile.UserName]; if (currentMember == null) continue; currentUser = new AggregatedUser(); currentUser.Email = currentMember.Email; currentUser.FirstName = GetStringValue(webProfile, "FirstName"); currentUser.LastName = GetStringValue(webProfile, "LastName"); currentUser.Roles = Roles.GetRolesForUser(profile.UserName); currentUser.Username = profile.UserName; allUsers.Add(currentUser); } return allUsers; } private String GetStringValue(ProfileBase profile, String valueName) { if (profile == null) return String.Empty; var propValue = profile.PropertyValues[valueName]; if (propValue == null) return String.Empty; return propValue.PropertyValue as String; } 

Is there a better (simpler, more efficient) way

  • Get all custom profile information from the profile provider and
  • combine them with membership provider information to show them, for example. on the admin page?

I looked at Web Profile Builder , but IMO it only provides intellisense development for user profile properties by creating a proxy class.

+4
source share

You are not saved in the database until you call Save :

Save recording method changed profile property values ​​for source data. A profile provider can reduce the amount of activity on a data source by performing only updates when the IsDirty property is set to true. This refers to the default SqlProfileProvider.

0
source share

All Articles