public IEnumerable <T> As <T>() where T : class { var options = new GetItemsByFuncOptions((database) => _item.Children); options.Copy(_getModelOptions); return(new LazyItemEnumerable <T>(options, _service, _lazyLoadingHelper)); }
/// <summary> /// Maps data from the CMS value to the .Net property value /// </summary> /// <param name="mappingContext">The mapping context.</param> /// <returns>System.Object.</returns> public override object MapToProperty(AbstractDataMappingContext mappingContext) { var scConfig = Configuration as SitecoreLinkedConfiguration; var scContext = mappingContext as SitecoreDataMappingContext; var item = scContext.Item; var linkDb = global::Sitecore.Globals.LinkDatabase; var options = new GetItemsByFuncOptions(); options.Copy(mappingContext.Options); scConfig.GetPropertyOptions(options); options.ItemsFunc = new Func <Database, IEnumerable <Item> >(database => { //ME - i am not sure this is correct but there is an odd behaviour of references // languges come back as invariant, going with default language in this scenario var references = new Func <IEnumerable <Item> >(() => { var itemLinks = linkDb.GetReferences(item); return(itemLinks.Select(x => x.GetTargetItem())); }); IEnumerable <Item> items; switch (scConfig.Option) { case SitecoreLinkedOptions.All: var itemLinks1 = references(); var itemLinks2 = linkDb.GetReferrers(item); items = itemLinks1.Union(itemLinks2.Select(x => x.GetSourceItem())); break; case SitecoreLinkedOptions.References: items = references(); break; case SitecoreLinkedOptions.Referrers: var itemLinks4 = linkDb.GetReferrers(item); items = itemLinks4.Select(x => x.GetSourceItem()); break; default: items = new List <Item>(); break; } return(items); }); var result = scContext.Service.GetItems(options); return(result); }
/// <summary> /// Maps data from the CMS value to the .Net property value /// </summary> /// <param name="mappingContext">The mapping context.</param> /// <returns>System.Object.</returns> public override object MapToProperty(AbstractDataMappingContext mappingContext) { var scContext = mappingContext as SitecoreDataMappingContext; var scConfig = Configuration as SitecoreChildrenConfiguration; Func <Database, IEnumerable <Item> > getItems = (database) => ItemManager.GetChildren(scContext.Item, SecurityCheck.Enable, ChildListOptions.None); var options = new GetItemsByFuncOptions(getItems); options.Copy(mappingContext.Options); scConfig.GetPropertyOptions(options); return(scContext.Service.GetItems(options)); }