Esempio n. 1
0
        public static async Task Inserts <T>(string collectionName, IEnumerable <T> values, NoSQLType type = NoSQLType.MongoDB, IClientSessionHandle clientSession = null, INoSQLDbConnection connection = null) where T : MongDBBaseModel
        {
            if (connection != null)
            {
                var collection = connection.Database.GetCollection <T>(collectionName);
                await collection.InsertManyAsync(values);
            }
            else
            {
                switch (type)
                {
                case NoSQLType.MongoDB:
                    using (INoSQLDbConnection conn = new MongoSqlConnection(NoConnectionString, NoSqlDatabase))
                    {
                        var collection = connection.Database.GetCollection <T>(collectionName);
                        await collection.InsertManyAsync(values);
                    }
                    break;

                default:
                    throw new Exception("Wrong type");
                }
            }
        }
Esempio n. 2
0
        public static async Task <IEnumerable <T> > Query <T>(string collectionName, Func <T, bool> query, NoSQLType type = NoSQLType.MongoDB, IClientSessionHandle clientSession = null, INoSQLDbConnection connection = null)
        {
            if (connection != null)
            {
                var collection = connection.Database.GetCollection <T>(collectionName);
                return(await((IMongoQueryable <T>)(collection.AsQueryable().Where(query))).ToListAsync());
            }
            else
            {
                switch (type)
                {
                case NoSQLType.MongoDB:
                    using (INoSQLDbConnection conn = new MongoSqlConnection(NoConnectionString, NoSqlDatabase))
                    {
                        var collection = conn.Database.GetCollection <T>(collectionName);
                        return(await((IMongoQueryable <T>)(collection.AsQueryable().Where(query))).ToListAsync());
                    }

                default:
                    throw new Exception("Wrong type");
                }
            }
        }