EFCore.MongoDB is a MongoDB mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. EFCore.MongoDB works with MongoDB through a provider plugin API.
EFCore.MongoDB is available on NuGet.
dotnet add package IoTSharp.EntityFrameworkCore.MongoDB
We recommend using the daily builds to get the latest code and provide feedback on EF Core. These builds contain latest features and bug fixes; previews and official releases lag significantly behind.
The following code demonstrates basic usage of EFCore.MongoDB . For a full tutorial configuring the DbContext
, defining the model, and creating the database, see getting started in the docs.
using (var db = new BloggingContext())
{
// Inserting data into the database
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
db.SaveChanges();
// Querying
var blog = db.Blogs
.OrderBy(b => b.BlogId)
.First();
// Updating
blog.Url = "https://devblogs.microsoft.com/dotnet";
blog.Posts.Add(
new Post
{
Title = "Hello World",
Content = "I wrote an app using EF Core!"
});
db.SaveChanges();
// Deleting
db.Remove(blog);
db.SaveChanges();
}
Most people use EFCore.MongoDB by installing pre-build NuGet packages, as shown above. Alternately, the code can be built and packages can be created directly on your development machine.
We welcome community pull requests for bug fixes, enhancements, and documentation. See How to contribute for more information.
If you have a specific question about using these projects, we encourage you to ask it on Stack Overflow. If you encounter a bug or would like to request a feature, submit an issue. For more details, see getting support.