Beispiel #1
0
        /// <summary>
        /// Builds the criteria.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <param name="dependencyCriterion">The dependency criterion.</param>
        public virtual void BuildCriteria(DetachedCriteria criteria, Junction dependencyCriterion)
        {
            if (criteria == null)
            {
                ThrowHelper.ThrowArgumentNullException("criteria");
            }

            if (FieldName.Contains(".") && !FieldName.ToLower().StartsWith("id."))
            {
                CreateDetachedCriteria(criteria, FieldName, dependencyCriterion);
            }
            else
            {
                string           fieldName = string.Empty;
                AssociationEntry e         = null;
                if (!FieldName.ToLower().Contains("id."))
                {
                    Dictionary <string, AssociationEntry> ascs = GetAssociations();
                    if (ascs.ContainsKey(FieldName))
                    {
                        e = ascs[FieldName];
                    }
                    else
                    {
                        e           = new AssociationEntry(FieldName, FieldName, string.Format("p{0}", Stopwatch.GetTimestamp().ToString()));
                        ascs[e.Key] = e;
                    }
                    fieldName = string.Format("{0}.{1}", criteria.Alias, e.Association);
                }
                else
                {
                    fieldName = string.IsNullOrEmpty(criteria.Alias) ? FieldName : string.Format("{0}.{1}", criteria.Alias, FieldName);
                }

                if (mCriterion == null)
                {
                    mCriterion = BuildCriterion(fieldName);
                }
                if (dependencyCriterion != null)
                {
                    dependencyCriterion.Add(mCriterion);
                }
                else
                {
                    criteria.Add(mCriterion);
                }
            }
        }
Beispiel #2
0
        private void CreateNextPropertyLevel(DetachedCriteria criteria, List <string> propertyList, int listPointer, Junction dependencyCriterion)
        {
            Dictionary <string, AssociationEntry> ascs = GetAssociations();

            string           associationKey = GetAssociationKey(propertyList, listPointer);
            AssociationEntry e = null;

            if (ascs.ContainsKey(associationKey))
            {
                e = ascs[associationKey];
                if (listPointer == propertyList.Count - 1)
                {
                    if (mCriterion == null)
                    {
                        mCriterion = BuildCriterion(e.Association);
                    }
                    if (dependencyCriterion != null)
                    {
                        dependencyCriterion.Add(mCriterion);
                    }
                    else
                    {
                        criteria.Add(mCriterion);
                    }
                }
                else
                {
                    DetachedCriteria subCriteria = e.Criteria;
                    if (subCriteria == null)
                    {
                        subCriteria = criteria.CreateCriteria(e.Association, e.Alias, JoinType.InnerJoin);
                        e.Criteria  = subCriteria;
                    }
                    listPointer++;
                    CreateNextPropertyLevel(subCriteria, propertyList, listPointer, dependencyCriterion);
                }
            }
            else
            {
                bool isThisId = associationKey.ToLower().EndsWith(".id");
                if (listPointer == 0)
                {
                    e = new AssociationEntry(propertyList[0], propertyList[0], string.Format("p{0}{1}", Stopwatch.GetTimestamp().ToString(), listPointer.ToString()));
                }
                else
                {
                    string           parentAssociation = GetAssociationKey(propertyList, listPointer - 1);
                    AssociationEntry parentEntry       = ascs[parentAssociation]; // léteznie kell, máskülönben ide sem juthattam volna
                    e = new AssociationEntry(associationKey, string.Format("{0}.{1}", parentEntry.Alias, propertyList[listPointer]), string.Format("p{0}{1}", Stopwatch.GetTimestamp().ToString(), listPointer.ToString()));
                }
                if (!isThisId)
                {
                    // az id asszociációkat nem mentjük le
                    ascs[e.Key] = e;
                }

                if (listPointer == propertyList.Count - 1 || isThisId)
                {
                    if (mCriterion == null)
                    {
                        mCriterion = BuildCriterion((isThisId && listPointer < propertyList.Count - 1) ? string.Format("{0}.{1}", e.Association, propertyList[listPointer + 1]) : e.Association);
                    }
                    if (dependencyCriterion != null)
                    {
                        dependencyCriterion.Add(mCriterion);
                    }
                    else
                    {
                        criteria.Add(mCriterion);
                    }
                }
                else
                {
                    DetachedCriteria subCriteria = e.Criteria;
                    if (subCriteria == null)
                    {
                        subCriteria = criteria.CreateCriteria(e.Association, e.Alias, JoinType.InnerJoin);
                        e.Criteria  = subCriteria;
                    }
                    listPointer++;
                    CreateNextPropertyLevel(subCriteria, propertyList, listPointer, dependencyCriterion);
                }
            }
        }