Esempio n. 1
0
        public void setup()
        {
            _mongo = MongoTestHelper.create_new_database_connection();
            _provider = new MongoQueryProvider(_mongo);

            _mongo.Database.DropCollection(typeof (Book).Name);
        }
 public void TestConstructorWithOneArgument()
 {
     var provider = new MongoQueryProvider(_collection);
     var iqueryable = (IQueryable)new MongoQueryable<C>(provider);
     Assert.AreSame(typeof(C), iqueryable.ElementType);
     Assert.AreSame(provider, iqueryable.Provider);
 }
 /// <summary>
 /// Translate a MongoDB LINQ query.
 /// </summary>
 /// <param name="provider">The MongoDB query provider.</param>
 /// <param name="expression">The LINQ query expression.</param>
 /// <returns>A TranslatedQuery.</returns>
 public static TranslatedQuery Translate(MongoQueryProvider provider, Expression expression)
 {
     expression = PartialEvaluator.Evaluate(expression, provider.CanBeEvaluatedLocally);
     // assume for now it's a SelectQuery
     var documentType = GetDocumentType(expression);
     var selectQuery = new SelectQuery(provider.Collection, documentType);
     selectQuery.Translate(expression);
     return selectQuery;
 }
 public void TestCreateQueryNonGeneric()
 {
     var expression = collection.AsQueryable<C>().Expression;
     var provider = new MongoQueryProvider(collection);
     var query = provider.CreateQuery(expression);
     Assert.AreSame(typeof(C), query.ElementType);
     Assert.AreSame(provider, query.Provider);
     Assert.AreSame(expression, query.Expression);
 }
Esempio n. 5
0
        public void ConfigureQuerying()
        {
            var mongoQueryProvider = new MongoQueryProvider(_queryConfiguration.DatabaseName,
                _queryConfiguration.Server,
                _queryConfiguration.ServerPort,
                _queryConfiguration.Options);

            ObjectFactory.Configure(configure =>
                {
                    configure.For<IMongoQueryProvider>().Use(mongoQueryProvider);
                    configure.For<IMongoDatabase>().Use(mongoQueryProvider.Db);
                });
        }
 public void TestConstructor()
 {
     var provider = new MongoQueryProvider(collection);
 }
Esempio n. 7
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main( string[] args )
        {
            var mongo = new Mongo( "myorders", "localhost", "27017", string.Empty );
            // For Linq to work, collection name must match Class name.
            MongoCollection< Order > collection = mongo.GetCollection< Order >( "Order" );

            var provider = new MongoQueryProvider(mongo);
            var orderQueryable = new MongoQuery< Order >( provider );

            DeleteAllDocumentsFromCollection( collection );
            CreateAndInsertSingleDocumentIntoCollection( collection );
            CreateAndInsertMultipleDocumentIntoCollection( collection );
            UpdateDocument( collection );
            UpdateUsingAtomicIncrement(collection);
            QueryFromCollection( collection );
            QueryUsingLinq( orderQueryable );
            QueryAllDocuments(orderQueryable);

            QueryConditionalOperators( collection );
            QueryConditionalOperatorsUsingLinq(orderQueryable);

            Console.WriteLine( "\n Press Enter to Exit." );
            Console.ReadLine();
        }