Esempio n. 1
0
        public ProjectionResult Generate()
        {
            var queryPlanBuilder = new QueryPlanBuilder(_projectionAtom, _allAtoms);

            var queryPlan = queryPlanBuilder.Build();
            var viewName  = $"view_{_projectionAtom.Name}";

            GenerateSql(viewName, queryPlan);

            return(new ProjectionResult
            {
                References = queryPlan.References,
                Meta = new SqlAccessorMetadata
                {
                    Name = viewName,
                    BaseAtom = new ProjectedAtomRoot
                    {
                        Name = _projectionAtom.Name,
                        Members = queryPlan.QueryMembers.ToList()
                    },
                    QueryType = QueryType.View
                },
                Sql = GenerateSql(viewName, queryPlan),
                Name = Constants.DefaultSchema + "." + viewName
            });
        }
        internal ProjectionResult Generate()
        {
            var result = new ProjectionResult
            {
            };

            QueryPlanBuilder builder = new QueryPlanBuilder(Projection, _allAtoms);
            var plan = builder.Build();
            QuerySqlGenerator query = new QuerySqlGenerator(plan);

            query.Generate();
        }
        internal ProjectionResult Generate()
        {
            var result = new ProjectionResult
            {

            };

            QueryPlanBuilder builder = new QueryPlanBuilder(Projection, _allAtoms);
            var plan = builder.Build();
            QuerySqlGenerator query = new QuerySqlGenerator(plan);
            query.Generate();
        }
        public IEnumerable<Code.ProjectedAtomRoot> GetProjections(IEnumerable<ProjectionAtom> projections)
        {
            foreach (var projection in projections)
            {
                var queryBuilder = new QueryPlanBuilder(projection, _allAtoms.Where(i => i.AdditionalInfo.Schema == Constants.DefaultSchema).ToDictionary(i => i.Name));

                var columns = queryBuilder.GetProjectionColumns();

                if (projection.IgnoreConflicts)
                {
                    columns = columns.DistinctBy(i => i.Name);
                }

                var references = columns.ToList();

                yield return new Code.ProjectedAtomRoot
                             {
                                 Name = projection.Name,
                                 Members = references
                             };
            }
        }
        public IEnumerable <Code.ProjectedAtomRoot> GetProjections(IEnumerable <ProjectionAtom> projections)
        {
            foreach (var projection in projections)
            {
                var queryBuilder = new QueryPlanBuilder(projection, _allAtoms.Where(i => i.AdditionalInfo.Schema == Constants.DefaultSchema).ToDictionary(i => i.Name));

                var columns = queryBuilder.GetProjectionColumns();

                if (projection.IgnoreConflicts)
                {
                    columns = columns.DistinctBy(i => i.Name);
                }

                var references = columns.ToList();

                yield return(new Code.ProjectedAtomRoot
                {
                    Name = projection.Name,
                    Members = references
                });
            }
        }
Esempio 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;
        }
Esempio n. 7
0
        public void ViewGenWeird()
        {
            var roots = new List<AtomModel>
                        {
                            new AtomModel
                            {
                                Name = "CareOrgManager",
                                Members = new OrderedAtomMembers
                                          {
                                              new AtomMemberInfo
                                              {
                                                  Name = "CareProgramGuid",
                                                  Reference = new AtomReference
                                                              {
                                                                  Name = "CareProgram"
                                                              }
                                              }
                                          }
                            },
                            new AtomModel
                            {
                                Name = "CareOrg",
                                Members = new OrderedAtomMembers
                                          {
                                              new AtomMemberInfo
                                              {
                                                  Name = "CareOrgGuid"
                                              },
                                              new AtomMemberInfo
                                              {
                                                  Name = "CareOrgManagerGuid",
                                                  Reference = new AtomReference
                                                              {
                                                                  Name = "CareOrgManager"
                                                              }
                                              }
                                          }
                            },
                            new AtomModel
                            {
                                Name = "CareProgram",
                                Members = new OrderedAtomMembers()
                            },
                        };

            QueryPlanBuilder gen = new QueryPlanBuilder(
                new ProjectionAtom(
                    new Dictionary<string, List<string>>
                    {
                        {
                            "CareOrg", new List<string>
                                       {
                                           "A",
                                           "CareOrgManagerGuid"
                                       }
                        },
                        {
                            "CareOrgManager", new List<string>
                                              {
                                                  "CareOrgManagerGuid",
                                                  "B"
                                              }
                        },
                        { "CareProgram", new List<string>() },
                    }),
                roots.ToDictionary(a => a.Name));

            var result = gen.GetReferences();

            Console.WriteLine(string.Join("\r\n", result));
        }