私は、異なる特定のプロパティを持つ 3 種類のユーザー (顧客、サービス プロバイダー、および管理者) を持つ MVC プロジェクトに取り組み始めました。Visual Studio 2012 で、ASP.NET MVC Web アプリケーション インターネット アプリケーション テンプレートの既定の SimpleMembership 実装を拡張したいと考えています。
私は Customer クラスを持っています (Key 属性と関係についてはわかりません)
public class Customer
{
[Key]
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public virtual UserProfile UserProfile { get; set; }
}
SQL Server Express に Customer テーブルを作成します。
CREATE TABLE [dbo].[Customer]
(
[UserName] NVARCHAR(MAX) NOT NULL,
[FirstName] NVARCHAR(50) NOT NULL,
[LastName] NVARCHAR(50) NOT NULL,
[Phone] NVARCHAR(50) NULL
)
エンティティ フレームワークのコンテキスト:
public class UsersContext : DbContext
{
public UsersContext() : base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<Customer> Customers { get; set; }
}
UserProfile テーブルと共に Customer テーブルを作成するには、以下にどのコードを追加する必要がありますか?
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("Index", "Home");
}
前もって感謝します