Exemple #1
0
        public IEnumerable <dynamic> SelectManyRelatedTo(IEnumerable <dynamic> models, dynamic options)
        {
            if (DiscardCache(options))
            {
                selectManyRelatedToCache = null;
            }

            if (selectManyRelatedToCache != null)
            {
                return(selectManyRelatedToCache);
            }

            var many = Repository.Query(SelectClause(models.ToArray())).ToList();

            foreach (var item in many)
            {
                var model = models.First(s => s.Id == item.GetMember(fromColumn));

                item.SetMember(model.GetType().Name, new DynamicFunction(() => model));
            }

            selectManyRelatedToCache = new DynamicModels(many);

            return(selectManyRelatedToCache);
        }
Exemple #2
0
 public override void AddNewAssociationMethod(DynamicModels collection, dynamic model)
 {
     collection.SetMember(
         "New",
         new DynamicFunctionWithParam(attributes =>
     {
         return(EntityFor(model, attributes));
     }));
 }
Exemple #3
0
 private void AddNewAssociationMethod(DynamicModels collection, DynamicModel model)
 {
     collection.SetMember(
         "New",
         new DynamicFunctionWithParam(attributes =>
     {
         return(EntityFor(attributes));
     }));
 }
Exemple #4
0
        private DynamicFunctionWithParam Query(DynamicModel model)
        {
            return((options) =>
            {
                if (DiscardCache(options))
                {
                    cachedCollection = null;
                }

                if (cachedCollection != null)
                {
                    return cachedCollection;
                }

                cachedCollection = new DynamicModels(Repository.Query(SelectClause(model)));

                AddNewAssociationMethod(cachedCollection, model);

                return cachedCollection;
            });
        }
Exemple #5
0
        public DynamicModels Execute(dynamic options,
                                     DynamicRepository repository,
                                     string associationName,
                                     string selectClause,
                                     IEnumerable <dynamic> models,
                                     string parentMemberName)
        {
            if (ShouldDiscardCache(options))
            {
                Cache = null;
            }

            if (Cache != null)
            {
                return(Cache);
            }

            var many = repository.Query(selectClause).ToList();

            foreach (var item in many)
            {
                var model = models.First(s => s.Id == item.GetMember(parentMemberName));

                item.SetMember(model.GetType().Name, model);
            }

            foreach (var model in models)
            {
                var assocation = model.AssociationNamed(associationName);

                var relatedTo = many.Where(s => s.GetMember(model.GetType().Name).Equals(model)).Select(s => s);

                assocation.EagerLoadMany.Cache = new DynamicModels(relatedTo);

                assocation.AddNewAssociationMethod(assocation.EagerLoadMany.Cache, model);
            }

            return(new DynamicModels(many));
        }
Exemple #6
0
        private bool EagerLoad(string collectionName, object[] args, out object result)
        {
            result = new HashSet <dynamic>();

            if (!Models.Any())
            {
                return(true);
            }

            dynamic options = null;

            if (args.Any())
            {
                options = args[0];
            }

            foreach (var m in Models)
            {
                var association = m.AssociationNamed(collectionName);

                IEnumerable <dynamic> values = association.EagerLoad(Models, options);

                foreach (var v in values)
                {
                    (result as HashSet <dynamic>).Add(v);
                }

                if (association is SingleAssociation)
                {
                    break;
                }
            }

            result = new DynamicModels(result as HashSet <dynamic>);

            return(true);
        }
Exemple #7
0
 public override void AddNewAssociationMethod(DynamicModels collection, dynamic model)
 {
     collection.SetMember("New", NewItemDelegate(model));
 }
Exemple #8
0
 public virtual void AddNewAssociationMethod(DynamicModels collection, dynamic model)
 {
     collection.SetMember("New", NewItemDelegate());
 }
Exemple #9
0
 public virtual void AddRepository(DynamicModels collection, DynamicRepository repository)
 {
     collection.SetMember("Repository", repository);
 }