Search code examples
c#entity-frameworkmongodbasp.net-identity-2

EntityFramework 6 and mongodb and Identity


I am using WebAPi project and I would like to setup EntityFramework 6 with Mongodb.

I have setup my mongodb database and my entity framework code first model by following this link:

http://cdn.rssbus.com/help/DG1/ado/pg_efCodeFirst.htm

Now I would like to get Entity Framework and Asp.net Identity 2 to work together based on Mongodb. However, I cannot find any way ormodules that allow to do it. I found the following but it explains to uninstall entity framework.

https://github.com/g0t4/aspnet-identity-mongo

So would you know a tuorial or would you have any experiences to enable mongodb for EF Code first and with IDentity working with?

THanks,


Solution

  • Ok so I finally found a solution.

    I am not using EF anymore.

    I am using AspNet Identity Mongo with the V2 branch I compiled.

    https://github.com/InspectorIT/MongoDB.AspNet.Identity/tree/v2

    I am using MongoRepository for the repository of my Model.

    https://github.com/RobThree/MongoRepository

    And I have developed a DataService to manage my models CRUD operations.

     public class DataService
    {
        public static MongoRepository<ModelClass> ModelClass{ get { return Singleton<MongoRepository<ModelClass>>.Instance; } }
    
    
    }
    
    public class Singleton<T> where T : class, new()
    {
        Singleton() { }
    
        private static readonly Lazy<T> instance = new Lazy<T>(() => new T());
    
        public static T Instance { get { return instance.Value; } }
    }
    

    And I am good.

    Thanks,