public static List<ProductEntity> SearchForProductsByName(string name) { var bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(PredicateFactory.Like(ProductFieldIndex.Name, string.Format("%{0}%", name))); var productEntities = new EntityCollection(new ProductEntityFactory()); using (var adapter = new DataAccessAdapter()) { adapter.FetchEntityCollection(productEntities, bucket); } var products = new List<ProductEntity>(productEntities.Count); products.AddRange(productEntities.Cast<ProductEntity>()); return products; }
public static List<ProductSectionEntity> GetChildSections(int parentId) { EntityCollection sections = new EntityCollection(new ProductSectionEntityFactory()); IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(PredicateFactory.CompareValue(ProductSectionFieldIndex.ParentSectionId, ComparisonOperator.Equal, parentId)); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntityCollection(sections, filter); } List<ProductSectionEntity> sectionList = new List<ProductSectionEntity>(sections.Count); foreach (ProductSectionEntity pse in sections) { sectionList.Add(pse); } return sectionList; }
public static string[] FindRolesForUser(string username) { EntityCollection roles = new EntityCollection(new UserRoleLinkEntityFactory()); IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(PredicateFactory.CompareValue(UserRoleLinkFieldIndex.UserId, ComparisonOperator.Equal, username)); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntityCollection(roles, filter); } List<string> returnRoles = new List<string>(roles.Items.Count); foreach (UserRoleLinkEntity urle in roles) { returnRoles.Add(urle.RoleName); } return returnRoles.ToArray(); }
public static List<SpecialOfferEntity> GetSpecialOffers(short numberToReturn) { EntityCollection offers = new EntityCollection(new SpecialOfferEntityFactory()); IPrefetchPath2 pf = new PrefetchPath2((int)EntityType.SpecialOfferEntity); pf.Add(SpecialOfferEntity.PrefetchPathProduct).SubPath.Add(ProductEntity.PrefetchPathProductSection); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntityCollection(offers, null, numberToReturn, null, pf); } offers.SupportsSorting = true; offers.Sort((int) SpecialOfferFieldIndex.Number, ListSortDirection.Ascending); SpecialOfferEntity [] specialOffers = new SpecialOfferEntity[numberToReturn]; foreach (SpecialOfferEntity sof in offers) { specialOffers[sof.Number - 1] = sof; } return FillMissingOffers(specialOffers); }
private static EntityCollection LoadProductsForSection(IRelationPredicateBucket filter) { EntityCollection products = new EntityCollection(new ProductEntityFactory()); ISortExpression sorter = new SortExpression(); sorter.Add(SortClauseFactory.Create(ProductFieldIndex.SortIndex, SortOperator.Ascending)); IPrefetchPath2 pfVariations = new PrefetchPath2((int)EntityType.ProductEntity); pfVariations.Add(ProductEntity.PrefetchPathProductVariation); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntityCollection(products, filter, 0, sorter, pfVariations); } return products; }