示例#1
0
 /// <summary>
 /// 初始化类<see cref="DbContextBase{TModel}"/>。
 /// </summary>
 /// <param name="executor">数据库执行接口。</param>
 /// <param name="logger">日志接口。</param>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="sqlGenerator">脚本生成器。</param>
 /// <param name="visitorFactory">条件表达式解析器工厂实例。</param>
 public DbContext(IDatabase executor, ILogger <IDatabase> logger, ISqlHelper sqlHelper,
                  IQuerySqlGenerator sqlGenerator, IExpressionVisitorFactory visitorFactory)
     : base(executor, logger, sqlHelper, sqlGenerator, visitorFactory)
 {
     _executor = executor;
     _logger   = logger;
 }
示例#2
0
 /// <summary>
 /// 初始化类<see cref="DbContextBase{TModel}"/>。
 /// </summary>
 /// <param name="executor">数据库执行接口。</param>
 /// <param name="logger">日志接口。</param>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="sqlGenerator">脚本生成器。</param>
 /// <param name="visitorFactory">条件表达式解析器工厂实例。</param>
 public DbTransactionContext(IDbExecutor executor, ILogger logger, ISqlHelper sqlHelper,
                             IQuerySqlGenerator sqlGenerator, IExpressionVisitorFactory visitorFactory)
     : base(executor, logger, sqlHelper, sqlGenerator, visitorFactory)
 {
     _executor       = executor;
     _visitorFactory = visitorFactory;
 }
示例#3
0
 /// <summary>
 /// 初始化类<see cref="QueryContext{TModel}"/>。
 /// </summary>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="visitorFactory">表达式解析工厂接口。</param>
 /// <param name="sqlGenerator">SQL脚本生成接口。</param>
 /// <param name="db">数据库接口。</param>
 public QueryContext(ISqlHelper sqlHelper, IExpressionVisitorFactory visitorFactory, IQuerySqlGenerator sqlGenerator, IDbExecutor db)
 {
     _visitorFactory = visitorFactory;
     _sqlGenerator   = sqlGenerator;
     _db             = db;
     SqlHelper       = sqlHelper;
     Entity          = typeof(TModel).GetEntityType();
 }
示例#4
0
 /// <summary>
 /// 初始化类<see cref="DbContextBase{TModel}"/>。
 /// </summary>
 /// <param name="executor">数据库执行接口。</param>
 /// <param name="logger">日志接口。</param>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="sqlGenerator">脚本生成器。</param>
 /// <param name="visitorFactory">条件表达式解析器工厂实例。</param>
 protected DbContextBase(IDbExecutor executor, ILogger logger, ISqlHelper sqlHelper, IQuerySqlGenerator sqlGenerator, IExpressionVisitorFactory visitorFactory)
 {
     Logger          = logger;
     SqlHelper       = sqlHelper;
     SqlGenerator    = sqlGenerator;
     _executor       = executor;
     _visitorFactory = visitorFactory;
     EntityType      = typeof(TModel).GetEntityType();
 }
示例#5
0
        public static IRelationalCommand Generate(
            this DbContext dbContext,
            SelectExpression databaseExpression,
            IReadOnlyDictionary <string, object> parameters = null)
        {
            IQuerySqlGeneratorFactory sqlGeneratorFactory = dbContext.GetService <IQuerySqlGeneratorFactory>();
            IQuerySqlGenerator        sqlGenerator        = sqlGeneratorFactory.CreateDefault(databaseExpression);

            return(sqlGenerator.GenerateSql(parameters ?? new Dictionary <string, object>()));
        }
示例#6
0
        public static Func <DbDataReader, TResult> GetMaterializer <TResult>(
            this DbContext dbContext,
            SelectExpression databaseExpression,
            IReadOnlyDictionary <string, object> parameters = null)
        {
            IMaterializerFactory       materializerFactory = dbContext.GetService <IMaterializerFactory>();
            Func <ValueBuffer, object> materializer        = (Func <ValueBuffer, object>)materializerFactory
                                                             .CreateMaterializer(
                entityType: dbContext.Model.FindEntityType(typeof(TResult)),
                selectExpression: databaseExpression,
                projectionAdder: (property, expression) => expression.AddToProjection(
                    property, databaseExpression.QuerySource),
                typeIndexMap: out _)
                                                             .Compile();
            IQuerySqlGeneratorFactory            sqlGeneratorFactory = dbContext.GetService <IQuerySqlGeneratorFactory>();
            IQuerySqlGenerator                   sqlGenerator        = sqlGeneratorFactory.CreateDefault(databaseExpression);
            IRelationalValueBufferFactoryFactory valueBufferFactory  = dbContext.GetService <IRelationalValueBufferFactoryFactory>();

            return(dbReader => (TResult)materializer(sqlGenerator.CreateValueBufferFactory(valueBufferFactory, dbReader).Create(dbReader)));
        }