Ejemplo n.º 1
0
        public LtConnectionTests()
        {
            var rand = new RandomEx(0);

            _container = new Container();

            _container.RegisterDelegate <IDbConnection>(() => new SqlConnectionFactory().Create(), reuse: Reuse.Scoped);

            new DryIoc.Module().Register(_container);
            var tableRegistrator = _container.Resolve <ITableDefinitionRegistrator>();

            tableRegistrator.Register(() => new NonRelationEntityDefinition());


            _entities = new SqlConnectionFactory().GetEntities();

            var tableResolver = _container.Resolve <ITableDefinitionResolver>();
            var dbConnection  = new SqlConnectionFactory().Create();
            var sqlBuilder    = new SQLiteSqlBuilder(tableResolver);

            _connection = new LtConnection(tableResolver, sqlBuilder, dbConnection);

            _allQuery    = new Query <NonRelationEntity>();
            _singleQuery = new Query <NonRelationEntity>(where : new EqualOperator(new Property <NonRelationEntity>(nameof(NonRelationEntity.Id)), new Parameter("Id")));
        }
Ejemplo n.º 2
0
        public int LtQuery()
        {
            var accum = 0;

            using (var container = new Container())
            {
                new global::LtQuery.ORM.DryIoc.Module().Register(container);

                var tableRegistrator = container.Resolve <global::LtQuery.ORM.ITableDefinitionRegistrator>();
                tableRegistrator.Register(() => new LtQuery.Tables.TestEntityDefinition());

                var tableResolver = container.Resolve <global::LtQuery.ORM.ITableDefinitionResolver>();
                var sqlBuilder    = new SqlServerSqlBuilder(tableResolver);
                using (var dbConnection = new SqlConnectionFactory().Create())
                    using (var connection = new LtConnection(tableResolver, sqlBuilder, dbConnection))
                    {
                        var singleQuery = Lt.Query <TestEntity>().Where(_ => _.Id == Lt.Arg <int>()).ToImmutable();
                        var entity      = connection.Single(singleQuery, new { Id = 1 });
                        AddHashCode(ref accum, entity.Id);
                    }
                return(accum);
            }
        }