Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?

I am new to ASP.NET MVC 5 and so I am trying to use it as much as possible to learn it by practice.

So I am thinking of using the new OWIN implementation of ASP.NET MVC to implement the authentication and authorization of my project. That said, I am building the project in a way that it can work with various types of databases.

So far I have used generic ADO.NET elements (e.g. DbDataReader etc) and I have refused to use any ORM. So I am wondering if I can go ahead with using the new identity system of ASP.NET or will I be bound to Entity Framework and SQL Server if I do so?

like image 640
Aref Avatar asked Mar 26 '14 05:03

Aref


People also ask

Do you have to use Entity Framework with MVC?

No it is not a must. You can implement your database layer.

What is difference between MVC and Entity Framework?

MVC is framework mainly concentrates on how you deliver a webpage from server to client. Entity framework is an object relational mapper which helps you to abstract different types of databases (MSSQL,MySQL etc) and helps querying objects instead of having sql strings in our project.

Is it .NET framework and Entity Framework are same?

These are 2 different things as mentioned before. Entity Framework is an ORM -> a Mapper to help you get data. asp.net is a framework to STRUCTURE your project ,with Objects and Classes, not related to entity.


1 Answers

Not that simple. Not that hard either.

You'll have to write your custom implementation of:

  1. IUserStore<TUser>
  2. IUserPasswordStore<TUser>
  3. IUserTwoFactorStore<TUser>
  4. IUserClaimStore<TUser>
  5. IRoleStore<TRole>
  6. IUserSecurityStampStore<TUser, string>
  7. IUserRoleStore<TUser, string>
  8. UserManager<TUser>

Then create your own user implementation, from IUser<TKey>, like:

public class MyUser : IUser<string> {     public string Id { get; set; }     public string UserName { get; set; } } 

Finally, from NuGet, remove AspNet.Identity.EntityFramework, which will remove EntityFramework too if you're not using it elsewhere.

Wherever your code breaks, rewrite it to use your custom implementations.

Tip

Create a MyUserRepository which implements items from 1 to 7.

Then, create a MyUserManager which implements item 8.

It will be damn easy to wire that up in place of default AspNet.Identity.EntityFramework classes.

like image 117
Anderson Matos Avatar answered Sep 18 '22 12:09

Anderson Matos