public CustomQueryStoredProcedureGenerator(ProjectionAtom projection, IEnumerable <AtomModel> allAtoms)
 {
     Projection = projection;
     _allAtoms  = allAtoms.ToDictionary(a => a.Name);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public static ProjectionResult MakeView(ProjectionAtom projection, IEnumerable <AtomModel> allAtoms)
 {
     return(new ViewGenerator(projection, allAtoms).Generate());
 }
Exemplo n.º 4
0
 public static ProjectionResult MakeQuery(ProjectionAtom projection, IEnumerable <AtomModel> allAtoms)
 {
     return(new CustomQueryStoredProcedureGenerator(projection, allAtoms).Generate());
 }
Exemplo n.º 5
0
 public ViewGenerator(ProjectionAtom projectionAtom, IEnumerable <AtomModel> allAtoms)
 {
     _projectionAtom = projectionAtom;
     _allAtoms       = allAtoms.ToDictionary(a => a.Name);
 }
Exemplo n.º 6
0
 public QueryPlanBuilder(ProjectionAtom projectionAtom, Dictionary <string, AtomModel> allAtoms)
 {
     Projection = projectionAtom;
     _allAtoms  = allAtoms;
 }