mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Using content item's ContentManager for lazy field loading instead of the injected one (#8761)
This commit is contained in:
parent
44bfa390bc
commit
90dc993e83
@ -65,7 +65,8 @@ namespace Orchard.Taxonomies.Handlers {
|
|||||||
var tempField = field.Name;
|
var tempField = field.Name;
|
||||||
field.TermsField.Loader(() => {
|
field.TermsField.Loader(() => {
|
||||||
var fieldTermRecordIds = part.Record.Terms.Where(t => t.Field == tempField).Select(tci => tci.TermRecord.Id);
|
var fieldTermRecordIds = part.Record.Terms.Where(t => t.Field == tempField).Select(tci => tci.TermRecord.Id);
|
||||||
var terms = _contentManager.GetMany<TermPart>(fieldTermRecordIds, VersionOptions.Published, queryHint);
|
// Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields.
|
||||||
|
var terms = part.ContentItem.ContentManager.GetMany<TermPart>(fieldTermRecordIds, VersionOptions.Published, queryHint);
|
||||||
return terms.ToList();
|
return terms.ToList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,7 +74,8 @@ namespace Orchard.Taxonomies.Handlers {
|
|||||||
part._termParts = new LazyField<IEnumerable<TermContentItemPart>>();
|
part._termParts = new LazyField<IEnumerable<TermContentItemPart>>();
|
||||||
part._termParts.Loader(() => {
|
part._termParts.Loader(() => {
|
||||||
var ids = part.Terms.Select(t => t.TermRecord.Id).Distinct();
|
var ids = part.Terms.Select(t => t.TermRecord.Id).Distinct();
|
||||||
var terms = _contentManager.GetMany<TermPart>(ids, VersionOptions.Published, queryHint)
|
// Using context content item's ContentManager instead of injected one to avoid lifetime scope exceptions in case of LazyFields.
|
||||||
|
var terms = part.ContentItem.ContentManager.GetMany<TermPart>(ids, VersionOptions.Published, queryHint)
|
||||||
.ToDictionary(t => t.Id, t => t);
|
.ToDictionary(t => t.Id, t => t);
|
||||||
return
|
return
|
||||||
part.Terms.Select(
|
part.Terms.Select(
|
||||||
|
Loading…
Reference in New Issue
Block a user