Beispiel #1
0
        public static A AddSibling <A>(IAbstractDal pSource, IOrdinal pOrdinal, bool pAddToQuery, string pCustomKey, bool pReadOnly = false, CustomKeyHand pHand = CustomKeyHand.Left)
            where A : IAbstractDal, new()
        {
            A lReturn = default(A);

            if (pAddToQuery || pOrdinal.SiblingsBitwise())
            {
                lReturn        = new A();
                lReturn.Parent = pSource;
                pSource.Query.AddEntityLeftJoinCustomKey(lReturn, pSource.EntityAlias, pCustomKey, pHand, pReadOnly);
                lReturn.GetOrdinal(pOrdinal);
            }
            else if (pSource.EntityAlias == "1" && pSource.Persistence && !pReadOnly)
            {
                lReturn = new A();
                pSource.Query.SaveAtributes.Add(pCustomKey, string.Concat("@", pCustomKey));
            }

            return(lReturn);
        }
Beispiel #2
0
        public string AppendNotExists(IAbstractDal pFromEntity, object pExistsValue, IAbstractDal pExistsEntity, CustomKeyHand pKeyHand, bool pAutoClose = true)
        {
            var lKeyHand    = string.Empty;
            var lParameter  = string.Concat(pFromEntity.Entity, "_", pExistsEntity.Entity);
            var lEntityFrom = string.Empty;

            switch (pKeyHand)
            {
            case CustomKeyHand.Left:
                lKeyHand = pFromEntity.EntityKey;
                break;

            case CustomKeyHand.Right:
                lKeyHand = pExistsEntity.EntityKey;
                break;
            }

            if (string.IsNullOrEmpty(pFromEntity.EntityAlias))
            {
                lEntityFrom = string.Concat("[", pFromEntity.Database, "].[", pFromEntity.Schema, "].[", pFromEntity.Entity, "]");
            }
            else
            {
                lEntityFrom = string.Concat("[", pFromEntity.EntityAlias, "]");
            }

            if (ParenthesesOpen)
            {
                Builder.Append(" ");
            }
            else
            {
                Builder.Append(" and ");
            }

            if (pAutoClose)
            {
                Builder.AppendFormat("not exists(select 1 from [{0}].[{1}].[{2}] ex{5} where ex{5}.[{4}] = {3}.[{4}] and ex{5}.[{3}] = @{5} and ex{5}.[{6}] = 1)",
                                     pExistsEntity.Database,
                                     pExistsEntity.Schema,
                                     pExistsEntity.Entity,
                                     lEntityFrom,
                                     lKeyHand,
                                     lParameter,
                                     string.Concat(pExistsEntity.EntityKey.Remove(pExistsEntity.EntityKey.LastIndexOf('_')), "_ativo")).AppendLine();
            }
            else
            {
                Builder.AppendFormat("not exists(select 1 from [{0}].[{1}].[{2}] ex{5} where ex{5}.[{4}] = {3}.[{4}] and ex{5}.[{3}] = @{5} and ex{5}.[{6}] = 1",
                                     pExistsEntity.Database,
                                     pExistsEntity.Schema,
                                     pExistsEntity.Entity,
                                     lEntityFrom,
                                     lKeyHand,
                                     lParameter,
                                     string.Concat(pExistsEntity.EntityKey.Remove(pExistsEntity.EntityKey.LastIndexOf('_')), "_ativo"));
            }


            QueryParameters.Add(string.Concat("@", lParameter), pExistsValue);

            return(string.Concat("ex", lParameter));
        }
Beispiel #3
0
 public static A AddSibling <A>(IAbstractDal pSource, IOrdinal pOrdinal, bool pAddToQuery, string pCustomKey, CustomKeyHand pHand = CustomKeyHand.Left)
     where A : IAbstractDal, new()
 {
     return(AddSibling <A>(pSource, pOrdinal, pAddToQuery, pCustomKey, false, pHand));
 }
Beispiel #4
0
        public void AppendEntity(int pValue, IAbstractDal pEntity, string pCustomKey, CustomKeyHand pKeyHand)
        {
            var lKeyLeftHand  = string.Empty;
            var lKeyRightHand = string.Empty;

            switch (pKeyHand)
            {
            case CustomKeyHand.Left:
                lKeyLeftHand  = pCustomKey;
                lKeyRightHand = pEntity.EntityKey;
                break;

            case CustomKeyHand.Right:
                lKeyRightHand = pCustomKey;
                lKeyLeftHand  = pEntity.EntityKey;
                break;

            case CustomKeyHand.Both:
                lKeyLeftHand = lKeyRightHand = pCustomKey;
                break;
            }

            var lParameter = string.Concat("@", pEntity.EntityAlias, lKeyRightHand);

            if (ParenthesesOpen)
            {
                Builder.Append(" ");
            }
            else
            {
                Builder.Append(" and ");
            }

            Builder.Append(string.Concat("[", pEntity.EntityAlias, "].[", lKeyLeftHand, "] = ", lParameter)).AppendLine();

            QueryParameters.Add(lParameter, pValue);
        }