Ejemplo n.º 1
0
        public void OrderByTest()
        {
            using (IBulkedDbConnection bulk = FConnection.CreateBulkedDbConnection())
            {
                bulk.Insert(new OrmType {
                    Id = Guid.NewGuid(), Order = 1
                }, new OrmType {
                    Id = Guid.NewGuid(), Order = 2
                });

                bulk.Flush();
            }

            SqlExpression <OrmType> expression = FConnection.From <OrmType>();

            expression.PrefixFieldWithTableName = true;

            ISqlQuery query = new OrmLiteSqlQuery(expression);

            query.Select(typeof(OrmType).GetProperty(nameof(OrmType.Order)), typeof(OrmType).GetProperty(nameof(OrmType.Order)));
            query.OrderBy(typeof(OrmType).GetProperty(nameof(OrmType.Order)));
            query.OrderByDescending(typeof(OrmType).GetProperty(nameof(OrmType.Id)));

            List <OrmType> result = query.Run <OrmType>(FConnection);

            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Order, Is.EqualTo(1));
            Assert.That(result[1].Order, Is.EqualTo(2));
        }
Ejemplo n.º 2
0
        public void JoinTest()
        {
            Guid id = Guid.NewGuid();

            using (IBulkedDbConnection bulk = FConnection.CreateBulkedDbConnection())
            {
                bulk.Insert(new OrmType {
                    Id = id
                });
                bulk.Insert(new OrmTypeWithReference {
                    Id = Guid.NewGuid(), Reference = id
                });

                bulk.Flush();
            }

            SqlExpression <OrmType> expression = FConnection.From <OrmType>();

            ISqlQuery query = new OrmLiteSqlQuery(expression);

            query.Select(typeof(OrmType).GetProperty(nameof(OrmType.Id)), typeof(MyView).GetProperty(nameof(MyView.Azonosito)));
            query.InnerJoin(typeof(OrmType).GetProperty(nameof(OrmType.Id)), typeof(OrmTypeWithReference).GetProperty(nameof(OrmTypeWithReference.Reference)));

            List <MyView> result = query.Run <MyView>(FConnection);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result.Single().Azonosito, Is.EqualTo(id));
        }
Ejemplo n.º 3
0
        public void SelectTest()
        {
            Guid id = Guid.NewGuid();

            FConnection.Insert(new OrmType {
                Id = id
            });

            SqlExpression <OrmType> expression = FConnection.From <OrmType>();

            ISqlQuery query = new OrmLiteSqlQuery(expression);

            query.Select(typeof(OrmType).GetProperty(nameof(OrmType.Id)), typeof(MyView).GetProperty(nameof(MyView.Azonosito)));

            List <MyView> result = query.Run <MyView>(FConnection);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result.Single().Azonosito, Is.EqualTo(id));
        }