How to do authentication in MVC application with linq?

4

I have a project in ASP.Net MVC and I am putting the authentification manually. Everything is going well, but I used as a reference an already ready project that uses the EntityFramework, but I want to use linq for my operations. The problem is occurring in the code below:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

The error generated is:

  

Error 2 The type 'System.Data.Entity.DbContext' is defined in an   assembly that is not referenced. You must add a reference to assembly   'EntityFramework, Version = 6.0.0.0, Culture = neutral,   PublicKeyToken = b77a5c561934e089 '.

Well, how could I solve this problem without using EntityFramework? Is there any way to use linq only for secure authentication? I researched a lot, but I did not find anything like it.

    
asked by anonymous 28.05.2015 / 13:53

1 answer

1

The error occurs because you added the Entity Framework in your project in an irregular way. The correct thing is to add per package. Open the Package Manager Console ( View > Other Windows & kb> Package Manager Console ) and type:

  

Install-Package EntityFramework -Version 6.1.2

Try not to install beta versions. As of the date of this answer, there are two beta versions in development.

The command not only installs the package for you correctly but also configures some files with entries that are required for the Entity Framework to be recognized, such as Web.config of the root directory.

This solves the problem that generates the error, but does not rule out using the Entity Framework, which I believe is the purpose of the question.

In this case, it is wrong for you to use a class derived from IdentityDbContext because IdentityDbContext is part of the Entity Framework .

The correct one is you derive another class called SignInManager , which is part of OWIN , Web standard set by Microsoft:

public class MinhaImplementacaoDeSignInManager : SignInManager<MinhaClasseDeUsuario, string>
{
    // Implemente os métodos aqui
}

MinhaClasseDeUsuario needs to implement the Microsoft.AspNet.Identity.IUser<TKey> .

If you need more help with the methods, I can further refine the question.

    
28.05.2015 / 15:54