使用Entity Framework和我自己的数据库创建自定义配置文件提供程序

时间:2013-07-22 14:11:46

标签: c# asp.net-mvc asp.net-profiles profile-provider

到目前为止,我可以创建Custom Membership ProviderCustom Role Provider,但我对Custom Profile Provider有疑问。在查看了一些演示之后,我发现他们使用web.config来定义配置文件的架构。例如,在代码<profile>

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

要访问该字段,他们会使用Profile.AddressNameProfile.AddressStreet等...

我的问题是:这是定义配置文件架构的唯一方法吗?如果我想在我的数据库中使用我的UserProfile表,我该怎么办?我需要阅读的方式来写数据。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

原始海报可能没有太多用处,但看起来您可以像described in this blog post那样使用。要点是,让生成的概要文件类继承您自己的类,该类又从ProfileBase继承,最后覆盖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>