Coder Social home page Coder Social logo

Comments (6)

crhairr avatar crhairr commented on June 6, 2024

It's already in the works! I've started a documentation branch for adding all of the relevant XML docs to the code as well for consumption with Intellisense.

from entityframeworkcore.

crhairr avatar crhairr commented on June 6, 2024

The first two wiki entries have been created:
https://github.com/crhairr/EntityFrameworkCore.MongoDb/wiki/Getting-Started

from entityframeworkcore.

ErikEJ avatar ErikEJ commented on June 6, 2024

Great - the use of attributes looks slightly strange in a EF Core context, in particular this:
[MongoDatabase("zooDb")] - could the UseMongoDb method be extended with a second parameters for the database name?

from entityframeworkcore.

crhairr avatar crhairr commented on June 6, 2024

Not currently, but you can configure the database in OnModelCreating (essentially what the attribute is doing):

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            new InternalModelBuilder(modelBuilder.Model.AsModel())
                .MongoDb(ConfigurationSource.Explicit)
                .FromDatabase("zooDb");
        }

This is quite clunky since Microsoft decided to split their builders into public and internal versions where the InternalModelBuilder takes a Model instead of an IMutableModel for some unobvious reason. This is why I prefer the attribute. I will probably end up adding a property to the options extension since that would be more concise than the above. But I think that anybody already familiar with the MongoDb C# driver would also prefer the straight-forward, declarative, aspect-oriented style of the attributes.

FWIF, the Bson* attributes are what the driver uses to create its BsonClassMap mappings, so I've implemented conventions to support those to make it easier for people already familiar with the driver to adopt this provider. I do intend at some point to add conventions to the adapter to support attributes used by EF Core (like Key and DatabaseGenerated) so that a BsonClassMap can be created from a "standard" EF Core model.

from entityframeworkcore.

vdavi avatar vdavi commented on June 6, 2024

This is fantastic! Can you tell me if there is built in support for accessing the .aggregate functionality for mongoDb?
I'v been spending months evaluating a completely different tech stack, (Meteor) and I've hit a dead end regarding aggregate usage while also using angular 2. (Long story)

from entityframeworkcore.

crhairr avatar crhairr commented on June 6, 2024

EDIT: this project wraps the MongoDB C# Driver, and DbSet<T> is essentially implemented as mongoDatabase.GetCollection<T>.AsQueryable<T>(). Anything that you can do with their Linq provider, you can do with a linq query using EFCore-MongoDB.

But, if you need more than that and must use the aggregation framework directly, read on...

END EDIT

It's possible, but there's currently no direct support for it through EFCore-MongoDB. I plan to expose this a bit more fluidly using extension methods on DbSet<T>. In the meantime, you should be able to use the MongoDB C# driver's aggregation framework by injecting an IMongoDbConnection into your class constructor and using it something like this:

public IEnumerable<T> AggregateTheThings<T>()
{
    var pipeline = new AggregateArgs()
    {
        /*do your thing here*/
    };
    return _mongoDbConnection
        .GetCollection<T>
        .Aggregate(pipeline);
}

You can find some examples of using the driver's Aggregate method here: http://mikaelkoskinen.net/post/mongodb-aggregation-framework-examples-in-c.

Note: you might encounter some issues if your collection contains polymorphic documents. Be sure to supply the base document type to GetCollection<T>. I already have a fix for this that will ensure that the correct collection for a polymorphic subtype is always returned, which will be committed in the next few days as part of an Identity provider for MongoDB.

from entityframeworkcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.