Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 375
dalton5 Avatar asked Aug 19 '15 15:08

dalton5


People also ask

Can we use Entity Framework core with MongoDB?

There is no official MongoDb provider implementation for EF core at this time, I did not see any mention of MongoDb in the . net core 7 (the next version) roadmap as of now.

Does Entity Framework work with NoSQL database?

When you use NoSQL databases for your infrastructure data tier, you typically do not use an ORM like Entity Framework Core. Instead you use the API provided by the NoSQL engine, such as Azure Cosmos DB, MongoDB, Cassandra, RavenDB, CouchDB, or Azure Storage Tables.

Can you mix dapper and Entity Framework?

Now that we have a running API that manages products and their prices using Entity Framework Core, we can now integrate Dapper into the solution and apply what we learned at the start of this article.


1 Answers

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,

like image 51
dalton5 Avatar answered Oct 02 '22 23:10

dalton5