public DbGateway(DatabaseType databaseType, string connectionString) { this.database = new Database(CreateDbProvider(databaseType, connectionString)); }
public DbGateway(string connectionStringSectionName) { this.database = new Database(DbProviderFactory.CreateDbProvider(connectionStringSectionName)); }
static Database() { if (DbProviderFactory.Default == null) { Default = null; } else { Default = new Database(DbProviderFactory.Default); } }
public DbGateway(Database database) { this.database = database; }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
public DbParameterCache(Database db) { this.db = db; }