Create Custom Profile Provider using Entity Framework with my own database

316 views Asked by At

Up to now, I can create Custom Membership Provider and Custom Role Provider, but I have problem with Custom Profile Provider. After looking at some demo, I've found out that they use web.config to define the schema for the Profile. For example, in the tag <profile>:

<properties> 
<add name="AddressName"/> 
<add name="AddressStreet"/> 
<add name="AddressCity"/> 
<add name="AddressState"/> 
<add name="AddressZipCode"/> 
<add name="AddressCountry"/> 
</properties>

To access that field, they use Profile.AddressName, Profile.AddressStreet, etc...

My question is: is that the only way to define the profile schema? If I want to use my UserProfile table in my database, what should I do? I need the way to read I write the data.

Thanks for your help.

1

There are 1 answers

0
Bouke On

Probably not much of use to the original poster, but it looks like you can do as described in this blog post. The gist is that you let the generated profile class inherit your own class which in turn inherits from ProfileBase, and finally override ProfileProvider:

    <profile inherits="Acme.MyApplication.ProfileCommon,MyApplication" defaultProvider="EfTableProfileProvider">
      <providers>
        <clear />        
        <add name="EfTableProfileProvider" type="Acme.MyApplication.EfTableProfileProvider,Facade" connectionStringName="ApplicationServices" applicationName="/MyApplication"/>
      </providers>
    </profile>