Click here to Skip to main content
12,300,379 members (53,154 online)
Click here to Skip to main content
Add your own
alternative version


90 bookmarked

ASP.NET Providers for the ADO.NET Entity Framework

, 15 Nov 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
The introduction of the ADO.NET Entity Framework implicitly created the need for ASP.NET providers such as membership, role and profile that leverage this new technology.


One of the most powerful improvements of ASP.NET 2.0 was truly the introduction of the membership, role and profile providers. They allow to rapidly integrate user management, role based security as well as visitor based page customization into your ASP.NET application. The name already indicates that they all implement the provider model design pattern.

Unfortunately, Microsoft doesn't have these providers ready to download leveraging the ADO.NET Entity Framework.

The downloadable source from this article provides a ready-to-use implementation for the above mentioned providers. The following article gives a quick overview about providers and it describes what it takes to get the provided source up and running.

In order to understand the source, sound knowledge of LINQ is inevitable. Furthermore, it is important that readers understand the philosophy behind ASP.NET providers.The following link gives a good overview of the ASP.NET providers.


Provider Model Design Pattern


The provider model pattern was designed to provide a configurable component for data access which is defined from the web.config. The Provider interfaces between the Business logic and Data Access. The actual concrete implementation of the provider is defined in the web.config. Custom providers can be built and configured in the web.config without changing the application design. Providers are a subclass of the ProviderBase class and typically instantiated using a factory method.

Various providers for the same purpose can co-exist and easily be configured in the web.config.

Database Schema

The database schema is closely related to the one that gets created by aspnet_regsql.exe:


The resulting Entity Model looks like the following:


Other than Microsoft's ASP.NET providers for SQL, the presented solution here does not use stored procedures. Instead, all the queries are implemented in the respective providers source using LINQ.

Exposed APIs

Membership Provider
void Initialize(string name, NameValueCollection config)

MembershipUser CreateUser(string username, string password, string email,
            string passwordQuestion, string passwordAnswer,
            bool isApproved,object providerUserKey, 
            out MembershipCreateStatus status)

bool ChangePasswordQuestionAndAnswer(string username, string password,
                string newPasswordQuestion, string newPasswordAnswer)

string GetPassword(string username, string answer)

bool ChangePassword(string username, string oldPassword, string newPassword)

string ResetPassword(string username, string answer)

void UpdateUser(MembershipUser membershipUser)

bool ValidateUser(string username, string password)

bool UnlockUser(string username)

MembershipUser GetUser(object providerUserKey, bool userIsOnline)

string GetUserNameByEmail(string email)

bool DeleteUser(string username, bool deleteAllRelatedData)

MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)

int GetNumberOfUsersOnline()

MembershipUserCollection FindUsersByName
	(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)

MembershipUserCollection FindUsersByEmail
	(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
Role Provider
void Initialize(string name, NameValueCollection config)

bool IsUserInRole(string username, string roleName)

string[] GetRolesForUser(string username)

void CreateRole(string roleName)

bool DeleteRole(string roleName, bool throwOnPopulatedRole)

bool RoleExists(string roleName)

void AddUsersToRoles(string[] userNames, string[] roleNames)

void RemoveUsersFromRoles(string[] userNames, string[] roleNames)

string[] GetUsersInRole(string roleName)

string[] GetAllRoles()

string[] FindUsersInRole(string roleName, string usernameToMatch)
Profile Provider
void Initialize(string name, NameValueCollection config) 

SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, 
				SettingsPropertyCollection properties)

void SetPropertyValues(SettingsContext context, 
		SettingsPropertyValueCollection properties)

int DeleteProfiles(ProfileInfoCollection profiles)

int DeleteProfiles(string[] usernames)

int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, 
			DateTime userInactiveSinceDate)

int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, 
				DateTime userInactiveSinceDate)

ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, 
				int pageIndex, int pageSize, out int totalRecords)

ProfileInfoCollection GetAllInactiveProfiles
		(ProfileAuthenticationOption authenticationOption, 
		DateTime userInactiveSinceDate, int pageIndex, 
		int pageSize, out int totalRecords)

ProfileInfoCollection FindProfilesByUserName
		(ProfileAuthenticationOption authenticationOption, 
		string usernameToMatch, int pageIndex, 
		int pageSize, out int totalRecords)

ProfileInfoCollection FindInactiveProfilesByUserName
		(ProfileAuthenticationOption authenticationOption, 
		string usernameToMatch, 
		DateTime userInactiveSinceDate, int pageIndex, 
		int pageSize, out int totalRecords)

How To Use the Provided Solution?

The three in this solution contained providers are connected but it shouldn't be too much work to pull them apart if not all of them are required. There are two ways to use the source:

  1. Use the provided Entity Model to connect to an existing or new database.
  2. Extend an existing database and hence the existing Entity Model and replace the data context used by the providers with the existing data context.

In general, the following steps have to be applied to get the first approach up and running:

  1. Create a new database (e.g., EFDataModel).
  2. Run the CreateTables.sql script located in the DatabaseScripts solution folder on the new database.
  3. Modify the connection string for the Entity Framework in the App.config file of the SmartSoft.EFProviders.DataLayer project.
  4. Modify connection string for the Entity Framework in the Web.config file of the Web application.
  5. Configure the providers in the Web.config as follows:
<!-- Membership configuration -->
<membership defaultProvider="EFMembershipProvider" userIsOnlineTimeWindow="15">
        <add name="EFMembershipProvider" 
              HelveticSolutions.EFProviders.Web, Version=, Culture=neutral,
             writeExceptionsToEventLog="true" />
<machineKey validationKey="C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA174257
<!-- Role configuration -->
<roleManager enabled="true" defaultProvider="EFRoleProvider">
        <add name="EFRoleProvider" 
              HelveticSolutions.EFProviders.Web, Version=, Culture=neutral, 
             connectionStringName="EFProviderConnection" />
<!-- Profile configuration -->
<profile enabled="true" 
        <add name="EFProfileProvider" 
              HelveticSolutions.EFProviders.Web, Version=, Culture=neutral, 


Wherever possible, LINQ queries were written to use expression trees rather than delegates. This article greatly describes the difference.


  • 29/10/2008 - Initial article posted
  • 01/08/2009 - New EFRoleProvider and EFProfileProvider, improved EFMembershipProvider
  • 14th November 2014 - Namespace corrected


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michael Ulmann
Architect Swissworx
Australia Australia
MCAD, MCPD Web Developer 2.0, MCPD Enterprise Developer 3.5

My company: Swissworx
My blog: Sitecore Experts

Hopp Schwiiz Smile | :)

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Humayun Kabir Mamun16-Nov-14 18:23
memberHumayun Kabir Mamun16-Nov-14 18:23 
GeneralError, when parse string for serialized Profile fields Pin
kavittoneghtandday15-Apr-11 0:20
memberkavittoneghtandday15-Apr-11 0:20 
GeneralRe: Error, when parse string for serialized Profile fields Pin
bleepzter27-Jun-11 14:32
memberbleepzter27-Jun-11 14:32 
GeneralRe: Error, when parse string for serialized Profile fields Pin
Michael Ulmann15-Nov-14 9:43
memberMichael Ulmann15-Nov-14 9:43 
GeneralMigration to EF4 and standart aspnet_regsql genrated structure Pin
CrazyMasterMC21-Feb-11 20:23
memberCrazyMasterMC21-Feb-11 20:23 
GeneralMy vote of 1 Pin
mobasshir15-Oct-10 7:09
membermobasshir15-Oct-10 7:09 
GeneralRe: My vote of 1 [modified] Pin
Michael Ulmann25-Oct-10 19:26
memberMichael Ulmann25-Oct-10 19:26 
QuestionHow to track anonymous user Pin
Member 740954115-Oct-10 2:07
memberMember 740954115-Oct-10 2:07 
QuestionDataAccess using Stored Procedures Pin
Pradeep Babu Yadagani2-Oct-10 21:18
memberPradeep Babu Yadagani2-Oct-10 21:18 
AnswerRe: DataAccess using Stored Procedures Pin
Michael Ulmann15-Nov-14 9:45
memberMichael Ulmann15-Nov-14 9:45 
Generalproblem in Upgrade to ASP.NET 2010 [modified] Pin
ir_programmer24-Jun-10 0:20
memberir_programmer24-Jun-10 0:20 
GeneralErrors in ProfileProvider.GetNumberOfInactiveProfiles(...) [modified] Pin
asmason6-Apr-10 7:16
memberasmason6-Apr-10 7:16 
GeneralRe: Errors in ProfileProvider.GetNumberOfInactiveProfiles(...) Pin
Michael Ulmann8-Apr-10 20:08
memberMichael Ulmann8-Apr-10 20:08 
GeneralErrors in ProfileProvider.GetAllProfiles() Pin
asmason6-Apr-10 7:10
memberasmason6-Apr-10 7:10 
GeneralErrors in ProfileProvider.GetAllInactiveProfiles(...) Pin
asmason6-Apr-10 7:04
memberasmason6-Apr-10 7:04 
GeneralErrors in ProfileProvider.FindProfilesByUserName(...) Pin
asmason6-Apr-10 6:49
memberasmason6-Apr-10 6:49 
GeneralErrors in ProfileProvider FindInactiveProfilesByUserName(...) [modified] Pin
asmason6-Apr-10 5:55
memberasmason6-Apr-10 5:55 
GeneralError in ProfileProvider Pin
asmason6-Apr-10 4:20
memberasmason6-Apr-10 4:20 
QuestionHow do we access the FirstName / LastName properties? Pin
rcbapb214-Feb-10 4:32
memberrcbapb214-Feb-10 4:32 
AnswerRe: How do we access the FirstName / LastName properties? Pin
Michael Ulmann15-Feb-10 17:31
memberMichael Ulmann15-Feb-10 17:31 
GeneralRe: How do we access the FirstName / LastName properties? Pin
rcbapb216-Feb-10 10:55
memberrcbapb216-Feb-10 10:55 
GeneralError in Role provider Pin
Member 456185410-Dec-09 8:40
memberMember 456185410-Dec-09 8:40 
GeneralRe: Error in Role provider Pin
Michael Ulmann10-Dec-09 14:04
memberMichael Ulmann10-Dec-09 14:04 
GeneralRe: Error in Role provider Pin
Member 456185410-Dec-09 19:19
memberMember 456185410-Dec-09 19:19 
QuestionVB.NET Version? Pin
Peki.HR17-Nov-09 3:07
memberPeki.HR17-Nov-09 3:07 
AnswerRe: VB.NET Version? [modified] Pin
Michael Ulmann19-Nov-09 19:08
memberMichael Ulmann19-Nov-09 19:08 
GeneralError in ProfileProvider [modified] Pin
Bidou448-Nov-09 21:57
memberBidou448-Nov-09 21:57 
GeneralRe: Error in ProfileProvider Pin
Farshid300315-Feb-11 23:40
memberFarshid300315-Feb-11 23:40 
GeneralRole provider GetUsersInRole(string roleName) bug Pin
coolbest122-Sep-09 0:49
membercoolbest122-Sep-09 0:49 
GeneralRe: Role provider GetUsersInRole(string roleName) bug Pin
Michael Ulmann22-Sep-09 14:39
memberMichael Ulmann22-Sep-09 14:39 
GeneralExcellent article, 5*****! Pin
DrABELL14-Sep-09 11:35
memberDrABELL14-Sep-09 11:35 
GeneralRe: Excellent article, 5*****! Pin
Michael Ulmann15-Nov-14 9:47
memberMichael Ulmann15-Nov-14 9:47 
GeneralRe: Excellent article, 5*****! Pin
DrABELL15-Nov-14 10:39
professionalDrABELL15-Nov-14 10:39 
QuestionProfile Pin
rayburnj9-Sep-09 3:56
memberrayburnj9-Sep-09 3:56 
AnswerRe: Profile Pin
Michael Ulmann17-Sep-09 16:00
memberMichael Ulmann17-Sep-09 16:00 
GeneralRe: Profile Pin
Member 45618549-Dec-09 20:27
memberMember 45618549-Dec-09 20:27 
GeneralRe: Profile Pin
Michael Ulmann9-Dec-09 23:45
memberMichael Ulmann9-Dec-09 23:45 
GeneralRe: Profile Pin
Member 456185410-Dec-09 8:43
memberMember 456185410-Dec-09 8:43 
GeneralRe: Profile Pin
Michael Ulmann10-Dec-09 11:32
memberMichael Ulmann10-Dec-09 11:32 
GeneralRe: Profile Pin
Member 456185410-Dec-09 19:20
memberMember 456185410-Dec-09 19:20 
Generalhelp in webconfige Pin
TGiril19-Aug-09 0:07
memberTGiril19-Aug-09 0:07 
GeneralConfiguration Error Pin
Kevin Slesinsky14-Aug-09 6:42
memberKevin Slesinsky14-Aug-09 6:42 
GeneralRe: Configuration Error Pin
Michael Ulmann16-Aug-09 18:40
memberMichael Ulmann16-Aug-09 18:40 
GeneralRe: Configuration Error Pin
Kevin Slesinsky19-Aug-09 8:13
memberKevin Slesinsky19-Aug-09 8:13 
GeneralUnlockUser Pin
Kevin Slesinsky20-Aug-09 10:32
memberKevin Slesinsky20-Aug-09 10:32 
GeneralGreat stuff! Pin
celtonthenet11-Aug-09 1:29
memberceltonthenet11-Aug-09 1:29 
GeneralRe: Great stuff! Pin
Michael Ulmann15-Nov-14 9:47
memberMichael Ulmann15-Nov-14 9:47 
GeneralProfile Provider with EF "normal" SQL Profile table Pin
shapper5-Aug-09 16:09
membershapper5-Aug-09 16:09 
GeneralSQL Script Pin
shapper5-Aug-09 3:12
membershapper5-Aug-09 3:12 
GeneralThanks. One suggestion and one question Pin
shapper3-Aug-09 14:54
membershapper3-Aug-09 14:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 15 Nov 2014
Article Copyright 2009 by Michael Ulmann
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid