Why not create a new context on WinForm project? Link , or create a DLL library for connection to database, then reference to this on your two projects,
I have similar projects today. I have an ASP.Net-MVC and a WinForm projects and a library for context and models, I made a library with models, migrations and context. I then added references to the library in my two projects, the only thing I have to do is add the connection string in both projects at App.Config or Web.Config and add references to EntityFramework and Asp.net-identity NugetPackages.
This is my code on WinForm to validate login, it is a void on Program Class:
public ApplicationUserManager UsrMan = new ApplicationUserManager(new ApplicationUserStore(new libProduccionDataBase.Contexto.DataBaseContexto())); public void CheckLogin( bool change = false ) { using (var loginfrm = new LogInForm()) { if (loginfrm.ShowDialog() == DialogResult.OK) { var t = Auxiliares.Validate(loginfrm.Response); if (t.isValid && UsrMan.FindByName( loginfrm.Response.UserName ) != null && UsrMan.CheckPassword( UsrMan.FindByName( loginfrm.Response.UserName ), loginfrm.Response.Password ) ) { Program.User = UsrMan.FindByName( loginfrm.Response.UserName ); } else { if (!t.isValid) { var str = new System.Text.StringBuilder(); t.Result.ToList().ForEach( err => { str.AppendFormat( "• {0}\n", err.ErrorMessage ); } ); MessageBox.Show( str.ToString(), "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error ); } CheckLogin(); } } else { if (!change) ExitThread(); } } }
This is the class for userManager:
public class ApplicationUserManager : UserManager<ApplicationUser, int> { public ApplicationUserManager( IUserStore<ApplicationUser, int> store ) : base( store ){} }
And the userStore (I use this because I personalize the id for user to int):
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public ApplicationUserStore(Contexto.DataBaseContexto context) : base(context) { } }