public static DatabaseQuery <T> WhereIn <T, K>(this DatabaseQuery <T> query, Expression <Func <T, object> > property,
                                                DatabaseQuery <K> subquery, Expression <Func <K, object> > targetProperty)
     where T : IEntity
     where K : IEntity
 {
     return((DatabaseQuery <T>)query.WhereIn(property.GetPropertyPath(), subquery, targetProperty.GetPropertyPath()));
 }
Esempio n. 2
0
        IEnumerable <IEntity> LoadTheAssociatedObjects(DatabaseQuery query)
        {
            var nestedQuery = Database.Of(Association.PropertyType);
            var provider    = nestedQuery.Provider;

            return(nestedQuery
                   .Where(provider.GetAssociationInclusionCriteria(query, Association))
                   .Include(IncludedNestedAssociations)
                   .GetList());
        }
Esempio n. 3
0
        internal override void Configure(DatabaseQuery query)
        {
            if (SqlCriteria.HasValue())
            {
                query.Where(new DirectDatabaseCriterion(SqlCriteria));
            }

            foreach (var item in Criterion.OrEmpty())
            {
                query.Where(item);
            }
        }
Esempio n. 4
0
        public DatabaseQuery CloneFor(Type type)
        {
            var result = new DatabaseQuery(type)
            {
                PageStartIndex = PageStartIndex,
                TakeTop        = TakeTop,
                PageSize       = PageSize
            };

            result.Criteria.AddRange(Criteria);
            result.include.Add(include);
            result.Parameters.Add(Parameters);

            return(result);
        }
        DatabaseQuery WhereSubquery(string myField, DatabaseQuery subquery, string targetField, string @operator)
        {
            subquery.AliasPrefix = "Subq" + Guid.NewGuid().ToString().Remove("-").Substring(0, 6);

            var sql = subquery.Provider
                      .GenerateSelectCommand(subquery, subquery.MapColumn(targetField));

            sql = $"{MapColumn(myField)} {@operator} ({sql})";
            Criteria.Add(Criterion.FromSql(sql));

            foreach (var subQueryParam in subquery.Parameters)
            {
                Parameters.Add(subQueryParam.Key, subQueryParam.Value);
            }

            return(this);
        }
Esempio n. 6
0
        public void LoadAssociations(DatabaseQuery query, IEnumerable <IEntity> mainObjects)
        {
            if (mainObjects.None())
            {
                return;
            }

            var associatedObjects = LoadTheAssociatedObjects(query);

            var groupedObjects = GroupTheMainObjects(mainObjects);

            var cachedField = query.EntityType.GetField("cached" + Association.Name,
                                                        BindingFlags.NonPublic | BindingFlags.Instance);

            if (cachedField == null)
            {
                return;
            }

            foreach (var associatedObject in associatedObjects)
            {
                var group = groupedObjects.GetOrDefault(associatedObject.GetId());
                if (group == null)
                {
                    if (query.PageSize.HasValue)
                    {
                        continue;
                    }

                    throw new Exception("Database include binding failed.\n" +
                                        "The loaded associated " + associatedObject.GetType().Name + " with id " + associatedObject.GetId() + "\n" + "is not referenced by any " + Association.DeclaringType.Name + "object!\n\n" +
                                        "All associated " + Association.Name + " Ids are:\n" +
                                        groupedObjects.Select(x => x.Key).ToLinesString());
                }

                foreach (var mainEntity in group)
                {
                    BindToCachedField(cachedField, associatedObject, mainEntity);
                }
            }
        }
 public static T WhereIn <T, K>(this T query, DatabaseQuery <K> subquery, Expression <Func <K, object> > targetProperty)
     where T : DatabaseQuery
     where K : IEntity
 => query.WhereIn(subquery, targetProperty.GetPropertyPath());
 public static DatabaseQuery <T> WhereIn <T>(this DatabaseQuery <T> query, Expression <Func <T, object> > property, DatabaseQuery subquery, string targetField)
     where T : IEntity
 => (DatabaseQuery <T>)query.WhereIn(property.GetPropertyPath(), subquery, targetField);
 public static T WhereIn <T>(this T query, DatabaseQuery subquery, string targetField)
     where T : DatabaseQuery
 => query.WhereIn <T>("ID", subquery, targetField);
 public static T WhereIn <T>(this T query, string myField, DatabaseQuery subquery, string targetField)
     where T : DatabaseQuery
 => (T)query.WhereIn(myField, subquery, targetField);
Esempio n. 11
0
 internal abstract void Configure(DatabaseQuery query);
Esempio n. 12
0
 public DatabaseCriterionSqlGenerator(DatabaseQuery query)
 {
     Query      = query;
     EntityType = query.EntityType;
 }
 public SqlCriterionGenerator(DatabaseQuery query) : base(query)
 {
 }
 internal override void Configure(DatabaseQuery query) => query.Page(StartIndex, PageSize);
 DatabaseQuery WhereNotIn(string myField, DatabaseQuery subquery, string targetField)
 {
     return(WhereSubquery(myField, subquery, targetField, "NOT IN"));
 }