Joined data no longer available in InfoProvider Typed Results GetValue
In KX13 and below, when you performed a join (Source
) using the InfoProvider classes, the joined data was returned with the TypedResult
and you could access it.
In Xperience by Kentico, if you map to the TypedResult (ex GetEnumeratedTypedResultAsync()
), that data is now scrubbed and not available.
example:
var items = await _mediaFileInfoProvider.Get()
.Source(x => x.InnerJoin<MediaLibraryInfo>(nameof(MediaFileInfo.FileLibraryID), nameof(MediaLibraryInfo.LibraryID)))
.Columns(nameof(MediaFileInfo.FileName), nameof(MediaLibraryInfo.LibraryDisplayName))
.GetEnumerableTypedResultAsync();
// KX13 and below this works
items.First().GetStringValue(nameof(MediaLibraryInfo.LibraryDisplayName), string.Empty);
// Xperience by Kentico this no longer returns
items.First().GetStringValue(nameof(MediaLibraryInfo.LibraryDisplayName), string.Empty);
Common use cases were to join on a Foreign Key ID field to the actual referenced entity so you could retrieve additional data.
(rhetorical question as I am going to answer with the answer), how do you retrieve this data in Xperience by Kentico?
Answers
In Xperience by Kentico, there is a new extension method GetDataContainerResultAsync()
that returns an IEnumerable of IDataContainer
(Xperience by Kentico's version of a DataRow).
You can then leverage these with the IInfoObject.New(IDataContainer data)
method, or use the .GetValue(string FieldName)
to retrieve the data.
var items = await _mediaFileInfoProvider.Get()
.Source(x => x.InnerJoin<MediaLibraryInfo>(nameof(MediaFileInfo.FileLibraryID), nameof(MediaLibraryInfo.LibraryID)))
.Columns(nameof(MediaFileInfo.FileName), nameof(MediaLibraryInfo.LibraryDisplayName))
.GetDataContainerResultAsync();
var firstIDataContainer = items.First();
// Can reference with GetValue
var libraryDisplayName = firstIDataContainer.GetValue(nameof(MediaLibraryInfo.LibraryDisplayName));
// Can also cast for strongly typed
var mediaInfoObject = MediaFileInfo.New(firstIDataContainer);
var mediaLibraryInfoObject = MediaLibraryInfo.New(firstIDataContainer);
var fileInfo = $"{mediaInfoObject.FileName} from Library {mediaLibraryInfoObject.LibraryDisplayName}";
To answer this question, you have to login first.