asp.net identity 가 기본적으로 entity framework 와 함께 샘플로 마소에서 제공해 줍니다.
이를 entity framework 를 제외하고 dapper.net 으로 도입시 치환해야 할 사항을 기재한 라이브러리 입니다.
해당 소스의 dapper 버전이 1.34 버전인데, 현재는 1.50 버전까지 나온 상태이므로 변경해 사용해 보면 좋을 듯 싶다.
https://github.com/whisperdancer/AspNet.Identity.Dapper
소스를 받아서 실행하면 몇가지 오류가 있어서 사용하는데 어려움이 있습니다. 수정한 사항을 기재해서 올립니다.
1. AspNet.Identity.Dapper\UserLoginsTable.cs
public List<UserLoginInfo> FindByUserId(int userId)
{
//return db.Connection.Query<UserLoginInfo>("Select * from MemberLogin where MemberId = @memberId", new {memberId=memberId }).ToList();
return db.Connection.Query<UserLoginInfoEx>("Select * from MemberLogin where UserId = @UserId", new { UserId = userId })
.Select(x => new UserLoginInfo(x.LoginProvider, x.ProviderKey))
.ToList();
}
2. UserLoginInfoEx.cs 클래스 생성 (위의 UserLoginsTable 클래스를 위함.)
namespace AspNet.Identity.Dapper
{
public class UserLoginInfoEx
{
/// <summary>
/// Provider for the linked login, i.e. Facebook, Google, etc.
/// </summary>
public string LoginProvider { get; set; }
/// <summary>
/// User specific key for the login provider
/// </summary>
public string ProviderKey { get; set; }
}
}
3. MemberLogin 테이블의 MemberID -> UserId 로 변경
CREATE TABLE [dbo].[MemberLogin](
[LoginProvider] [nvarchar](128) NOT NULL,
[ProviderKey] [nvarchar](128) NOT NULL,
[UserId] [int] NOT NULL,
CONSTRAINT [PK_dbo.MemberLogin] PRIMARY KEY CLUSTERED
(
[LoginProvider] ASC,
[ProviderKey] ASC,
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MemberLogin] WITH CHECK ADD CONSTRAINT [FK_dbo.MemberLogin_dbo.Member_MemberId] FOREIGN KEY([UserId])
REFERENCES [dbo].[Member] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[MemberLogin] CHECK CONSTRAINT [FK_dbo.MemberLogin_dbo.Member_MemberId]
GO
4. UserTable.cs 파일 수정
public void Update(TUser member)
{
db.Connection
.Execute(@"
Update Member set UserName = @userName, PasswordHash = @pswHash, SecurityStamp = @secStamp,
Email=@email, EmailConfirmed=@emailconfirmed, PhoneNumber=@phonenumber, PhoneNumberConfirmed=@phonenumberconfirmed,
AccessFailedCount=@accesscount, LockoutEnabled=@lockoutenabled, LockoutEndDateUtc=@lockoutenddate, TwoFactorEnabled=@twofactorenabled
WHERE Id = @memberId",
new
{
userName= member.UserName,
pswHash= member.PasswordHash,
secStamp= member.SecurityStamp,
memberId= member.Id,
email= member.Email,
emailconfirmed= member.EmailConfirmed,
phonenumber= member.PhoneNumber,
phonenumberconfirmed= member.PhoneNumberConfirmed,
accesscount= member.AccessFailedCount,
lockoutenabled= member.LockoutEnabled,
lockoutenddate= member.LockoutEndDateUtc,
twofactorenabled= member.TwoFactorEnabled
}
);
}