Beispiel #1
0
        public async Task LoadAssociations(DatabaseQuery query, IEnumerable <IEntity> mainObjects)
        {
            var associatedObjects = LoadTheAssociatedObjects(query);

            var groupedObjects = GroupTheMainObjects(mainObjects);

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

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

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

                    foreach (var mainEntity in group)
                    {
                        BindToCachedField(cachedField, associatedObject, mainEntity);
                    }
                }
            }
        }
Beispiel #2
0
 Task <IEnumerable <IEntity> > LoadTheAssociatedObjects(DatabaseQuery query)
 {
     return(Database.Instance.Of(Association.PropertyType)
            .Where(query.Provider.GetAssociationInclusionCriteria(query, Association))
            .Include(IncludedNestedAssociations)
            .GetList());
 }
Beispiel #3
0
        Task <IEnumerable <IEntity> > LoadTheAssociatedObjects(DatabaseQuery query)
        {
            var nestedQuery = Context.Current.Database().Of(Association.PropertyType);
            var provider    = ((DatabaseQuery)nestedQuery).Provider;

            return(nestedQuery
                   .Where(provider.GetAssociationInclusionCriteria(query, Association))
                   .Include(IncludedNestedAssociations)
                   .GetList());
        }
Beispiel #4
0
        public IDatabaseQuery 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);
        }
Beispiel #5
0
        public async Task LoadAssociations(DatabaseQuery query, IEnumerable <IEntity> mainObjects)
        {
            var associatedObjects = LoadTheAssociatedObjects(query);

            var groupedObjects = GroupTheMainObjects(mainObjects);

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

            if (cachedField != null)
            {
                foreach (var associatedObject in await associatedObjects)
                {
                    foreach (var mainEntity in groupedObjects[associatedObject.GetId()])
                    {
                        BindToCachedField(cachedField, associatedObject, mainEntity);
                    }
                }
            }
        }
        public override string GenerateWhere(DatabaseQuery query)
        {
            var r = new StringBuilder();

            if (SoftDeleteAttribute.RequiresSoftdeleteQuery(query.EntityType))
            {
                query.Criteria.Add(new Criterion("IsMarkedSoftDeleted", false));
            }

            r.Append($" WHERE { query.Column("ID")} IS NOT NULL");

            var whereGenerator = new SqlCriterionGenerator(query);

            foreach (var c in query.Criteria)
            {
                r.Append(whereGenerator.Generate(c).WithPrefix(" AND "));
            }

            return(r.ToString());
        }
Beispiel #7
0
 public PostgreSqlCriterionGenerator(DatabaseQuery query)
 {
     Query      = query;
     EntityType = query.EntityType;
 }
 protected DatabaseCriterionSqlGenerator(DatabaseQuery query)
 {
     Query      = query;
     EntityType = query.EntityType;
 }
Beispiel #9
0
 public virtual string GenerateWhere(DatabaseQuery query) =>
 SqlCommandGenerator.GenerateWhere(query);