static void test2() { var ctx = new DadeAfzaMongoDbContext(); ctx.OpenDatabase("Db_1"); MTable <Student> tb1 = new MTable <Student>(ctx, tableName2, ""); MTable <ClassRoom> tb2 = new MTable <ClassRoom>(ctx, tableName1, ""); MJoin <Student, ClassRoom> tb1tb2 = new MJoin <Student, ClassRoom>(tb1, tb2, "ClassId", "Id", new QueryDocument(), new List <KeyValuePair <string, string> >(), new List <KeyValuePair <string, string> >()); //Filter<Student> flt = new Filter<Student>(tb1, "{Age:{$gt:50}}"); //OfflineSort<Student> sort = new OfflineSort<Student>(flt, "Age", SortDirection.Ascending); var lst = tb1tb2.ToList(); Console.WriteLine($"{lst.Count}"); foreach (var item in lst) { Console.WriteLine($"{item.Age}"); } }
public ApiRunner(System.Text.Json.JsonDocument input) { this.input = input; this.context = new DadeAfzaMongoDbContext(); this.context.OpenDatabase("Db_1"); Parse(); }
public static void InsertData() { string tableName1 = "tbClass"; string tableName2 = "tbStudent"; string[] classNames = { "A", "B", "C", "D", "E", "F" }; string[] studentNames = { "Maysam", "Iman", "Amir", "Reza", "Morteza", "Hamid", "Abolfazl", "Mohamad", "Hasan", "Saeed" }; string[] teacherNames = { "Saeedi", "hosayni", "Sasani", "Mansori", "Babaie", "Ashrafi" }; var ctx = new DadeAfzaMongoDbContext(); ctx.OpenDatabase("Db_1"); var table1 = ctx.Database.GetCollection <MongoDynamicRecord>(tableName1); var table2 = ctx.Database.GetCollection <MongoDynamicRecord>(tableName2); Random rand = new Random(); for (int i = 1; i <= 6; i++) { MongoDynamicRecord ClassEntity = new MongoDynamicRecord() { Id = i, Data = new BsonDocument(new Dictionary <string, object>() { { "Name", classNames[i - 1] }, { "Capcity", rand.Next(25, 35) }, { "TeacherName", teacherNames[i - 1] } } ) }; table1.InsertOne(ClassEntity); } for (int i = 1; i < 210; i++) { MongoDynamicRecord StudentEntity = new MongoDynamicRecord() { Id = i, Data = new BsonDocument(new Dictionary <string, object>() { { "Name", studentNames[rand.Next(0, 9)] }, { "Age", rand.Next(1, 92) }, { "Gender", rand.Next(0, 1) }, { "ClassId", rand.Next(1, 6) }, } ) }; table2.InsertOne(StudentEntity); } }
static void test3() { var ctx = new DadeAfzaMongoDbContext(); ctx.OpenDatabase("Db_1"); var t1 = ctx.Database.GetCollection <BsonDocument>(tableName2); var t2 = ctx.Database.GetCollection <BsonDocument>(tableName1); var bb = t1.AsQueryable().Join(t2, _ => _["ClassId"], _ => _["_id"], (k1, k2) => new { k1, k2 }).ToList(); var tb1c = ctx.Database.GetCollection <Student>(tableName2).AsQueryable(); var tb2c = ctx.Database.GetCollection <ClassRoom>(tableName1).AsQueryable(); var j = from item1 in tb1c join item2 in tb2c on item1.ClassId equals item2.Id select new { item1, item2 }; var jj = j.ToList(); MPTable tb1 = new MPTable(ctx, tableName2, ""); MPTable tb2 = new MPTable(ctx, tableName1, "{_id:{$eq:2}}"); MPJoin tb1tb2 = new MPJoin(tb1, tb2, "ClassId", "Id", new QueryDocument(), new List <KeyValuePair <string, string> >(), new List <KeyValuePair <string, string> >()); //Filter<Student> flt = new Filter<Student>(tb1, "{Age:{$gt:50}}"); //OfflineSort<Student> sort = new OfflineSort<Student>(flt, "Age", SortDirection.Ascending); var lst = tb1tb2.ToList(); Console.WriteLine($"{lst.Count}"); //foreach (var item in lst) //{ // Console.WriteLine($"{item.Age}"); //} }
public Table(DadeAfzaMongoDbContext mongoDbContext, string entityName, string filter) { var qFilter = MongoDbHelper.ParseFilter(filter); BlockProvider = mongoDbContext.Database.GetCollection <BsonDocument>(entityName).AsQueryable();//.Where(_ => ((FilterDefinition<BsonDocument>)qFilter).Inject()); }
public Table(DadeAfzaMongoDbContext mongoDbContext, string entityName, QueryDocument filter) { BlockProvider = mongoDbContext.Database.GetCollection <BsonDocument>(entityName).AsQueryable();//.Where(_ => ((FilterDefinition<BsonDocument>)filter).Inject()); }
public QueryBuilder(string databaseName) { _databaseName = databaseName; _mongoDbContext = new DadeAfzaMongoDbContext(); _mongoDbContext.OpenDatabase(databaseName); }
public MTable(DadeAfzaMongoDbContext mongoDbContext, string entityName, string filter) { BlockProvider = mongoDbContext.Database.GetCollection <T>(entityName).AsQueryable();//.Where(_ => ((FilterDefinition<T>)MongoDbHelper.ParseFilter(filter)).Inject()); }
//public Table(DadeAfzaMongoDbContext mongoDbContext, string entityName, QueryDocument filter) //{ // BlockProvider = mongoDbContext.Database.GetCollection<T>(entityName).Where(_ => ((FilterDefinition<T>)filter).Inject()); //} public Table(DadeAfzaMongoDbContext mongoDbContext, string entityName, string filter) { BlockProvider = mongoDbContext.Database.GetCollection <T>(entityName).AsQueryable();//.Where(filter); }
public MPTable(DadeAfzaMongoDbContext mongoDbContext, string entityName, string filter) { BlockProvider = (IMongoQueryable <PureMongoDynamicRecord>)mongoDbContext.Database.GetCollection <PureMongoDynamicRecord>(entityName).AsQueryable();//.Where(_ => ((FilterDefinition<PureMongoDynamicRecord>)MongoDbHelper.ParseFilter(filter)).Inject()).AsQueryable(); }
static void Main(string[] args) { var ctx = new DadeAfzaMongoDbContext(); ctx.OpenDatabase("Db_1"); var tb11 = ctx.Database.GetCollection <BsonDocument>("tbStudent"); var tb22 = ctx.Database.GetCollection <BsonDocument>("tbClass"); var proj1 = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("Name", "SName"), new KeyValuePair <string, string>("Age", "SAge") }; var proj2 = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("Name", "CName"), new KeyValuePair <string, string>("TeacherName", "TeacherName") }; var sfilter = MongoDbHelper.ParseFilter("{SAge:{$gt:20}}"); Join join = new Join(tb11, tb22, "ClassId", "_id", sfilter, proj1, proj2); var cdrc = join.ToList(); var zel = ""; // var z = MongoDbHelper.ParseFilter("{_id:{$gt:10}}"); // var z2 = MongoDbHelper.ParseFilter("{_id:{$gt:3}}"); // var match1 = new BsonDocument("$match", z); // var match2 = new BsonDocument("$match", z2); // var lookup1 = new BsonDocument { { "$lookup", new BsonDocument { { "from", "tbClass" }, { "localField", "ClassId" }, { "foreignField", "_id" }, { "as", "Result" } } } }; // var projection = new BsonDocument{ { "$project" ,new BsonDocument { { "_id", 1 }, { "Name", 1 },{ "Result.Name",1 } } } }; //var pipeline = new[] {match2, lookup1 ,projection}; // var result = tb11.Aggregate<BsonDocument>(pipeline).ToList(); //var c= new BsonDocumentFilterDefinition<BsonDocument>(z); var studentProjection = new BsonDocument { { "$project", new BsonDocument { { "_id", 1 }, { "Name", 1 }, { "Age", 1 }, { "ClassId", 1 } } } }; var tbClassprojection = new BsonDocument { { "$project", new BsonDocument { { "_id", 1 }, { "Name", 1 }, { "Capcity", 1 }, { "TeacherName", 1 } } } }; var filterzz = MongoDbHelper.ParseFilter("{Name:'B'}"); var matcher = new BsonDocument("$match", filterzz); var pips = new[] { matcher, tbClassprojection }; //var tb22 = ctx.Database.GetCollection<BsonDocument>("tbClass"); var cp = tb11.Aggregate().Lookup(tb22, new BsonDocument(), pips, "as").ToList(); var prj = new BsonDocument { { "ClassName", "$result.Name" }, { "TName", "$result.TeacherName" } }; var selon = tb11.Aggregate().Lookup("tbClass", "ClassId", "_id", "result").Unwind(_ => _["result"]).Project(prj).ToList(); var cc = tb22.Aggregate().Lookup("tbStudent", "_id", "ClassId", "as").Unwind(_ => _["as"]).ToList(); var proj = Builders <BsonDocument> .Projection.Include(_ => _["Name"]) .Include(_ => _["Age"]) .Include(_ => _["joind.Name"]); var pppp = tb11.Aggregate().Lookup("tbClass", "ClassId", "_id", "joind").Unwind(_ => _["joind"]).Project(proj).ToList(); var tt = tb11.Find(new QueryDocument(MongoDbHelper.ParseFilter("{Age:{$gt:12}}"))).ToList(); var tb1 = ctx.Database.GetCollection <BsonDocument>("tbStudent"); var tb2 = ctx.Database.GetCollection <BsonDocument>("tbClass"); QueryDocument filter = new QueryDocument(MongoDbHelper.ParseFilter("{Age:{$gt:12}}")); var filterd = tb1.Find(filter); var sorted = filterd.SortByDescending(z => z["Name"]); var projected = sorted.Project(Builders <BsonDocument> .Projection.Include(p => p["Name"]).Include(p => p["Age"]).Include(p => p["ClassId"])); var jj = tb1.Aggregate().Lookup("tbClass", "ClassId", "_Id", @as: "TeacherName"); // jj.Match(Builders<BsonDocument>.Filter.Eq(z => z["Name"], "A")); var bbbb = jj.ToList(); var data = projected.ToList(); foreach (var row in data) { Console.WriteLine($"{row["Name"]}-(age: {row["Age"]})"); } Console.WriteLine($"Count: {data.Count()}"); Console.ReadLine(); }