Ejemplo n.º 1
0
        public void DbRefIndex_Test()
        {
            var mapper = new BsonMapper();

            mapper.Entity<DCustomer>()
                .Id(x => x.Login)
                .Field(x => x.Name, "customer_name");

            mapper.Entity<DOrder>()
                .Id(x => x.OrderNumber)
                .Field(x => x.Customer, "cust")
                .DbRef(x => x.Customer, "customers");

            using (var db = new LiteDatabase(new MemoryStream(), mapper))
            {
                var customer = new DCustomer { Login = "******", Name = "John Doe" };
                var order = new DOrder { OrderNumber = 1, Customer = customer };

                var customers = db.GetCollection<DCustomer>("Customers");
                var orders = db.GetCollection<DOrder>("Orders");

                customers.Insert(customer);
                orders.Insert(order);

                // create an index in Customer.Id ref
                // x.Customer.Login == "Customer.$id"
                orders.EnsureIndex(x => x.Customer.Login);

                var query = orders
                    .Include(x => x.Customer)
                    .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
Ejemplo n.º 2
0
        public void DbRefIndexe_Test()
        {
            var f = "";

            f = @"C:\Git\LiteDB\LiteDB.Shell\bin\Debug\_dbref.db";
            File.Delete(f);

            using (var db = new DbRefIndexDatabase(f))
            {
                var customer = new DCustomer {
                    Login = "******", Name = "John Doe"
                };
                var order = new DOrder {
                    OrderNumber = 1, Customer = customer
                };

                db.Customers.Insert(customer);
                db.Orders.Insert(order);

                // create an index in Customer.Id ref
                db.Orders.EnsureIndex(x => x.Customer.Login);

                var query = db.Orders
                            .Include(x => x.Customer)
                            .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
Ejemplo n.º 3
0
        public void DbRefIndexe_Test()
        {
            using (var db = new DbRefIndexDatabase())
            {
                var customer = new DCustomer { Login = "******", Name = "John Doe" };
                var order = new DOrder { OrderNumber = 1, Customer = customer };

                db.Customers.Insert(customer);
                db.Orders.Insert(order);

                // create an index in Customer.Id ref
                db.Orders.EnsureIndex(x => x.Customer.Login);

                var query = db.Orders
                    .Include(x => x.Customer)
                    .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
Ejemplo n.º 4
0
        public void DbRefIndex_Test()
        {
            var mapper = new BsonMapper();

            mapper.Entity <DCustomer>()
            .Id(x => x.Login)
            .Field(x => x.Name, "customer_name");

            mapper.Entity <DOrder>()
            .Id(x => x.OrderNumber)
            .Field(x => x.Customer, "cust")
            .DbRef(x => x.Customer, "customers");

            using (var db = new LiteDatabase(new MemoryStream(), mapper))
            {
                var customer = new DCustomer {
                    Login = "******", Name = "John Doe"
                };
                var order = new DOrder {
                    OrderNumber = 1, Customer = customer
                };

                var customers = db.GetCollection <DCustomer>("Customers");
                var orders    = db.GetCollection <DOrder>("Orders");

                customers.Insert(customer);
                orders.Insert(order);

                // create an index in Customer.Id ref
                // x.Customer.Login == "Customer.$id"
                orders.EnsureIndex(x => x.Customer.Login);

                var query = orders
                            .Include(x => x.Customer)
                            .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
Ejemplo n.º 5
0
        public void DbRefIndexe_Test()
        {
            var f = "";
            f = @"C:\Git\LiteDB\LiteDB.Shell\bin\Debug\_dbref.db";
            File.Delete(f);

            using (var db = new DbRefIndexDatabase(f))
            {
                var customer = new DCustomer { Login = "******", Name = "John Doe" };
                var order = new DOrder { OrderNumber = 1, Customer = customer };

                db.Customers.Insert(customer);
                db.Orders.Insert(order);

                // create an index in Customer.Id ref
                db.Orders.EnsureIndex(x => x.Customer.Login);

                var query = db.Orders
                    .Include(x => x.Customer)
                    .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }
Ejemplo n.º 6
0
        public void DbRefIndexe_Test()
        {
            using (var db = new DbRefIndexDatabase())
            {
                var customer = new DCustomer {
                    Login = "******", Name = "John Doe"
                };
                var order = new DOrder {
                    OrderNumber = 1, Customer = customer
                };

                db.Customers.Insert(customer);
                db.Orders.Insert(order);

                // create an index in Customer.Id ref
                db.Orders.EnsureIndex(x => x.Customer.Login);

                var query = db.Orders
                            .Include(x => x.Customer)
                            .FindOne(x => x.Customer.Login == "jd");

                Assert.AreEqual(customer.Name, query.Customer.Name);
            }
        }