public void Load(ILoadingContext loadingContext) { var lookupIds = loadingContext.ReferenceIds <TReference, TId>(); var references = _loadReferences(lookupIds); loadingContext.AddResults(references, reference => _getReferenceId(reference)); }
public Task LoadReferencesAsync(ILoadingContext loadingContext) { foreach (var referenceIds in loadingContext.ReferenceIds()) { LoadReference(referenceIds.Key, referenceIds.Value, loadingContext); } #if NETSTANDARD return(Task.CompletedTask); #else return(Task.FromResult(0)); #endif }
private void LoadImages(ILoadingContext loadingContext) { var lookupIds = loadingContext.ReferenceIds <Image, string>(); var references = lookupIds .Select(id => new Image { Id = id, Credits = id + "-credits", Url = id + "-url" } ) .ToList(); loadingContext.AddResults( references, reference => reference.Id ); }
public void Load(ILoadingContext loadingContext) { var lookupIds = loadingContext.ReferenceIds <ImageWithRatios, string>(); var repository = new ImageWithRatioRepository(); var images = repository.GetByDeclinaisonUrl(lookupIds); var imagesByDeclinaisonUrl = images.SelectMany( image => image.Ratios.Select(declinaison => new { DeclinaisonUrl = declinaison.Url, Image = image }) ) .ToDictionary( imageByDeclinaisonUrl => imageByDeclinaisonUrl.DeclinaisonUrl, imageByDeclinaisonUrl => imageByDeclinaisonUrl.Image); loadingContext.AddResults(imagesByDeclinaisonUrl); }
private void LoadBlogPosts(ILoadingContext loadingContext) { var lookupIds = loadingContext.ReferenceIds <BlogPost, int>(); var references = lookupIds .Select(id => new BlogPost { Id = id, Author = new Author { Name = "author-name-" + id, Email = "author-email-" + id, ImageId = "id-" + (id + 500) }, MultimediaContentRef = new MultimediaContentReference { Type = id % 2 == 0 ? "image" : "media", Id = id % 2 == 0 ? "id-" + id : (object)id }, TagIds = new List <int> { 88 + id, 89 + id }, Title = "Title-" + id } ) .ToList(); loadingContext.AddResults( references, reference => reference.Id ); }