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); }
public override void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember( "New", new DynamicFunctionWithParam(attributes => { return(EntityFor(model, attributes)); })); }
private void AddNewAssociationMethod(DynamicModels collection, DynamicModel model) { collection.SetMember( "New", new DynamicFunctionWithParam(attributes => { return(EntityFor(attributes)); })); }
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; }); }
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)); }
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); }
public override void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember("New", NewItemDelegate(model)); }
public virtual void AddNewAssociationMethod(DynamicModels collection, dynamic model) { collection.SetMember("New", NewItemDelegate()); }
public virtual void AddRepository(DynamicModels collection, DynamicRepository repository) { collection.SetMember("Repository", repository); }