Ejemplo n.º 1
0
 public DbGateway(DatabaseType databaseType, string connectionString)
 {
     this.database = new Database(CreateDbProvider(databaseType, connectionString));
 }
Ejemplo n.º 2
0
 public DbGateway(string connectionStringSectionName)
 {
     this.database = new Database(DbProviderFactory.CreateDbProvider(connectionStringSectionName));
 }
Ejemplo n.º 3
0
 static Database()
 {
     if (DbProviderFactory.Default == null)
     {
         Default = null;
     }
     else
     {
         Default = new Database(DbProviderFactory.Default);
     }
 }
Ejemplo n.º 4
0
 public DbGateway(Database database)
 {
     this.database = database;
 }
Ejemplo n.º 5
0
        public void Test_LambdaBuilderWhereClause_CombineCondition_QueryValueWithFieldWithCallMethod()
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            int topicId = 1000;
            int topicId1 = 2000;
            string content = "足球";
            string content1 = "篮球";
            DateTime datetime = DateTimeUtils.ToDateTime("2015-1-22").Value;

            WhereClauseBuildResult result = builder.BuildWhereClause(p => (p.TopicId < topicId || p.TopicId > topicId1) &&
                                                                          (p.Content.Contains(content) || p.Content.Contains(content1)) ||
                                                                           p.CreationDateTime < datetime);

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual(2000, result.ParameterValues.Values.ToList()[1]);

            Assert.AreEqual("%足球%", result.ParameterValues.Values.ToList()[2]);

            Assert.AreEqual("%篮球%", result.ParameterValues.Values.ToList()[3]);

            Assert.AreEqual(datetime, result.ParameterValues.Values.ToList()[4]);

        }
Ejemplo n.º 6
0
        public void Test_LambdaBuilderWhereClause_CombineCondition_QueryValueWithPropertyWithCallMethod() 
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            PostQueryRequest request = new PostQueryRequest();
            request.TopicId = 1000;
            request.MiscParams.TopicId = 2000;
            request.Content = "足球";
            request.MiscParams.Content = "篮球";
            request.CreationDateTimeParam.CreationDateTime = DateTimeUtils.ToDateTime("2015-1-22").Value;

            WhereClauseBuildResult result = builder.BuildWhereClause(p => (p.TopicId < request.TopicId || p.TopicId > request.MiscParams.TopicId) &&
                                                                          (p.Content.Contains(request.Content) || p.Content.Contains(request.MiscParams.Content)) ||
                                                                          (p.CreationDateTime < request.CreationDateTimeParam.CreationDateTime ||
                                                                           p.CreationDateTime.Equals(request.CreationDateTimeParam.CreationDateTime)));

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual(2000, result.ParameterValues.Values.ToList()[1]);

            Assert.AreEqual("%足球%", result.ParameterValues.Values.ToList()[2]);

            Assert.AreEqual("%篮球%", result.ParameterValues.Values.ToList()[3]);

            Assert.AreEqual(request.CreationDateTimeParam.CreationDateTime, result.ParameterValues.Values.ToList()[4]);

            Assert.AreEqual(request.CreationDateTimeParam.CreationDateTime, result.ParameterValues.Values.ToList()[5]);
        }
Ejemplo n.º 7
0
        public void Test_LambdaBuilderWhereClause_CombineCondition_QueryValueWithoutFieldAndPropertyWithCallMethod()
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            WhereClauseBuildResult result = builder.BuildWhereClause(p => (p.TopicId < 1000 || p.TopicId > 2000) &&
                                                                          (p.Content.Contains("足球") || p.Content.Contains("篮球")));

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual(2000, result.ParameterValues.Values.ToList()[1]);

            Assert.AreEqual("%足球%", result.ParameterValues.Values.ToList()[2]);

            Assert.AreEqual("%篮球%", result.ParameterValues.Values.ToList()[3]);
        }
Ejemplo n.º 8
0
        public void Test_LambdaBuilderWhereClause_QueryValueWithPropertyWithCallMethod()
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            PostQueryRequest request = new PostQueryRequest();
            request.TopicId = 1000;
            request.Content = "足球";
            request.CreationDateTimeParam.CreationDateTime = DateTimeUtils.ToDateTime("2015-1-22").Value;

            List<int> topicIds = new List<int>();
            topicIds.Add(1000);
            topicIds.Add(2000);
            topicIds.Add(3000);

            WhereClauseBuildResult result = builder.BuildWhereClause(p => p.TopicId.Equals(request.TopicId) &&
                                                                          p.Content.Contains(request.Content) &&
                                                                          p.CreationDateTime < request.CreationDateTimeParam.CreationDateTime);

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual("%足球%", result.ParameterValues.Values.ToList()[1]);

            Assert.AreEqual(request.CreationDateTimeParam.CreationDateTime, result.ParameterValues.Values.ToList()[2]);
        }
Ejemplo n.º 9
0
        public void Test_LambdaBuilderWhereClause_QueryValueWithoutFieldAndPropertyWithCallMethod()
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            DateTime datetime = DateTimeUtils.ToDateTime("2015-1-22").Value;

            WhereClauseBuildResult result = builder.BuildWhereClause(p => p.TopicId.Equals(1000) &&
                                                                          p.Content.Contains("足球") &&
                                                                          p.CreationDateTime < datetime);

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual("%足球%", result.ParameterValues.Values.ToList()[1]);

            Assert.AreEqual(datetime, result.ParameterValues.Values.ToList()[2]);
        }
Ejemplo n.º 10
0
        public void Test_LambdaBuilderWhereClause_QueryValueWithoutFieldAndPropertyNoCallMethod()
        {
            Database db = new Database(Eagle.Data.DbProviderFactory.Default);

            WhereClauseBuilder<Post> builder = db.DBProvider.CreateWhereClauseBuilder<Post>();

            WhereClauseBuildResult result = builder.BuildWhereClause(p => p.TopicId == 1000 && p.Content == "足球");

            string orderBy = builder.BuildOrderByClause(p => p.CreationDateTime);

            Assert.AreEqual(true, !string.IsNullOrEmpty(result.WhereClause));

            Assert.AreEqual(1000, result.ParameterValues.Values.ToList()[0]);

            Assert.AreEqual("足球", result.ParameterValues.Values.ToList()[1]);
        }
Ejemplo n.º 11
0
 public DbParameterCache(Database db)
 {
     this.db = db;
 }