public TemporalQuerySqlGenerator(
     QuerySqlGeneratorDependencies dependencies,
     QuerySqlGenerator inner,
     RelationalQueryContext ctx)
     : base(new QuerySqlGeneratorDependencies(
                new SingletonRelationalCommandBuilderFactory(dependencies.RelationalCommandBuilderFactory), dependencies.SqlGenerationHelper))
 {
     _sqlGenerationHelper = dependencies.SqlGenerationHelper;
     _ctx            = ctx;
     _commandbuilder = this.Dependencies.RelationalCommandBuilderFactory.Create();
 }
        internal ProjectionResult Generate()
        {
            var result = new ProjectionResult
            {

            };

            QueryPlanBuilder builder = new QueryPlanBuilder(Projection, _allAtoms);
            var plan = builder.Build();
            QuerySqlGenerator query = new QuerySqlGenerator(plan);
            query.Generate();
        }
Ejemplo n.º 3
0
        //https://stackoverflow.com/a/51583047
        public static string ToSql <TEntity>(this IQueryable <TEntity> query) where TEntity : class
        {
            IEnumerator <TEntity> enumerator = query.Provider.Execute <IEnumerable <TEntity> >(query.Expression).GetEnumerator();
            object                    relationalCommandCache = enumerator.Private("_relationalCommandCache");
            SelectExpression          selectExpression       = relationalCommandCache.Private <SelectExpression>("_selectExpression");
            IQuerySqlGeneratorFactory factory = relationalCommandCache.Private <IQuerySqlGeneratorFactory>("_querySqlGeneratorFactory");

            QuerySqlGenerator sqlGenerator = factory.Create();

            Microsoft.EntityFrameworkCore.Storage.IRelationalCommand command = sqlGenerator.GetCommand(selectExpression);

            string sql = command.CommandText;

            return(sql);
        }
Ejemplo n.º 4
0
        public string GenerateQuerySproc(
            string schemaName,
            string tableName, 
            string sprocSuffix, 
            string sprocParameters,
            QueryPlan plan)
        {
            AddDeletedItemFiltering(plan);

            QuerySqlGenerator query = new QuerySqlGenerator(plan, indentLevel: 1);
            return SprocHeader(schemaName, tableName, sprocSuffix, sprocParameters) + $@"

            {query.Generate()}

            END
            GO
            ";
        }
Ejemplo n.º 5
0
        public string GenerateQuerySproc(
            string schemaName,
            string tableName,
            string sprocSuffix,
            string sprocParameters,
            QueryPlan plan)
        {
            AddDeletedItemFiltering(plan);

            QuerySqlGenerator query = new QuerySqlGenerator(plan, indentLevel: 1);

            return(SprocHeader(schemaName, tableName, sprocSuffix, sprocParameters) + $@"

    {query.Generate()}

END
GO
");
        }
Ejemplo n.º 6
0
        public override StoredProcedureResult Generate()
        {
            var fields = new Dictionary <string, List <string> >
            {
                {
                    Atom.Name, Atom.Members.Select(i => i.Name)
                    .ToList()
                },
                {
                    _searchBy.Name, _searchBy.TargetMember.Atom.Members.Select(i => i.Name)
                    .ToList()
                }
            };

            var projectionAtom = new ProjectionAtom(fields);

            var builder = new QueryPlanBuilder(projectionAtom, _allAtoms.ToDictionary(i => i.Name));

            var plan = builder.Build();

            plan.QueryMembers = plan.QueryMembers.Where(i => i.Member.Atom.Name != _searchBy.Name && !i.Member.HasFlag(MemberFlags.Generated))
                                .ToList();

            var queryPlan = new QuerySqlGenerator(plan, 2).Generate()
                            .IndentAllLines(2, true);

            var sprocSuffix = $"ListBy{_searchBy.Member}";

            string
                Params        = GetTypedSprocParam(_searchBy.TargetMember),
                schema        = Atom.AdditionalInfo.Schema,
                Key           = _searchBy.Member,
                ExternalTable = _searchBy.Name,
                ExternalKey   = _searchBy.Member,
                TableName     = Atom.Name,
                SprocSuffix   = sprocSuffix;

            var template = SprocHeader(schema, TableName, SprocSuffix, Params) + $@"

        {queryPlan}
        WHERE
            [{schema}].[{ExternalTable}].{Key} = @{Key}	
END
GO
";

            var name = $"{schema}.{TableName}_ListBy{ExternalKey}";

            var result = new StoredProcedureResult
            {
                Name             = name,
                Sql              = template,
                AccessorMetadata = new SqlAccessorMetadata
                {
                    BaseAtom  = ProjectedAtomRoot.FromAtom(Atom),
                    QueryKey  = _searchBy.TargetMember,
                    QueryType = QueryType.GetOne,
                    Name      = name
                }
            };

            return(result);
        }
Ejemplo n.º 7
0
        public override StoredProcedureResult Generate()
        {
            var fields = new Dictionary<string, List<string>>
                         {
                             {
                                 Atom.Name, Atom.Members.Select(i => i.Name)
                                                .ToList()
                             },
                             {
                                 _searchBy.Name, _searchBy.TargetMember.Atom.Members.Select(i => i.Name)
                                                          .ToList()
                             }
                         };

            var projectionAtom = new ProjectionAtom(fields);

            var builder = new QueryPlanBuilder(projectionAtom, _allAtoms.ToDictionary(i => i.Name));

            var plan = builder.Build();

            plan.QueryMembers = plan.QueryMembers.Where(i => i.Member.Atom.Name != _searchBy.Name && !i.Member.HasFlag(MemberFlags.Generated))
                                    .ToList();

            var queryPlan = new QuerySqlGenerator(plan, 2).Generate()
                                                          .IndentAllLines(2, true);

            var sprocSuffix = $"ListBy{_searchBy.Member}";

            string
                Params = GetTypedSprocParam(_searchBy.TargetMember),
                schema = Atom.AdditionalInfo.Schema,
                Key = _searchBy.Member,
                ExternalTable = _searchBy.Name,
                ExternalKey = _searchBy.Member,
                TableName = Atom.Name,
                SprocSuffix = sprocSuffix;

            var template = SprocHeader(schema, TableName, SprocSuffix, Params) + $@"

            {queryPlan}
            WHERE
            [{schema}].[{ExternalTable}].{Key} = @{Key}
            END
            GO
            ";

            var name = $"{schema}.{TableName}_ListBy{ExternalKey}";

            var result = new StoredProcedureResult
                         {
                             Name = name,
                             Sql = template,
                             AccessorMetadata = new SqlAccessorMetadata
                                    {
                                        BaseAtom = ProjectedAtomRoot.FromAtom(Atom),
                                        QueryKey = _searchBy.TargetMember,
                                        QueryType = QueryType.GetOne,
                                        Name = name
                                    }
                         };

            return result;
        }
Ejemplo n.º 8
0
        private static (IRelationalCommand, IRelationalTypeMappingSource) GetRelationalComponents_v2(RelationalCommandCache relationalCommandCache, QuerySqlGenerator sqlGenerator, IReadOnlyDictionary <string, object> parameterValues)
        {
#pragma warning disable EF1001 // Internal EF Core API usage.
            var command = relationalCommandCache.GetRelationalCommand(parameterValues);
#pragma warning restore EF1001 // Internal EF Core API usage.
            var dependencies  = sqlGenerator.GetType().GetProperty("Dependencies", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sqlGenerator) as QuerySqlGeneratorDependencies;
            var mappingSource = dependencies.RelationalCommandBuilderFactory.Create().TypeMappingSource;

            return(command, mappingSource);
        }