エンティティフレームワークを使用してMVC3アプリにカスタムProfileProviderクラスを追加しようとしていますが、次のようなことを試みるたびにGetPropertyValuesが呼び出されることに気付きました。
profile.FirstName = viewModel.FirstName;
何らかの理由で、データベースの値を更新することができません。これまでに設定したものです。このチュートリアルを大まかにフォローしています: http ://www.davidhayden.com/blog/dave/archive/2007 / 10/30 / CreateCustomProfileProviderASPNET2UsingLINQToSQL.aspx
<profile enabled="true" defaultProvider="EfProfileProvider" inherits="Data.BOHProfile" automaticSaveEnabled="true">
<providers>
<clear />
<add name="EfProfileProvider" type="Data.Providers.EfProfileProvider" connectionStringName="BOHEntities" applicationName="BOH" />
</providers>
</profile>
プロファイルクラス:
public class BOHProfile : ProfileBase, IBOHProfile
{
public virtual string FirstName
{
get { return base["FirstName"] as string; }
set { base["FirstName"] = value; }
}
public virtual string LastName
{
get { return base["LastName"] as string; }
set { base["LastName"] = value; }
}
public virtual string City
{
get { return base["City"] as string; }
set { base["City"] = value; }
}
public static BOHProfile CurrentUser()
{
return (BOHProfile)(ProfileBase.Create(Membership.GetUser().UserName));
}
public static BOHProfile CurrentUser(string userName)
{
return (BOHProfile)(ProfileBase.Create(userName));
}
}
実際のプロバイダーのコードは次のとおりです。
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
var uow = new EfUnitOfWork();
var profileRepo = new ProfileRepository(new EfRepository<Profile>(), uow);
var data = profileRepo.FetchProfileData(context["UserName"].ToString(), ApplicationName);
return data != null ? ProviderUtility.ConvertToSettingsPropertyValueCollection(data) : null;
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
var data = ProviderUtility.ConvertFromSettingsPropertyValueCollection(collection);
var uow = new EfUnitOfWork();
var profileRepo = new ProfileRepository(new EfRepository<Profile>(), uow);
profileRepo.SaveProfileData(context["UserName"].ToString(), ApplicationName, data);
profileRepo.Save();
}
プロファイルプロバイダーのポイントがわからないかもしれませんが、プロファイルテーブルのデータを取得して設定するクラスを作成できたようです。または、おそらくで使用できるものが表示されていません。このプロファイル情報を設定したときのコントローラー?