本文整理汇总了C#中Rock.Model.AttributeService.AsNoTracking方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeService.AsNoTracking方法的具体用法?C# AttributeService.AsNoTracking怎么用?C# AttributeService.AsNoTracking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeService
的用法示例。
在下文中一共展示了AttributeService.AsNoTracking方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadCacheObjects
/// <summary>
/// Loads the cache objects.
/// </summary>
private void LoadCacheObjects( RockContext rockContext )
{
// Cache all the entity types
foreach ( var entityType in new Rock.Model.EntityTypeService( rockContext ).Queryable().AsNoTracking() )
{
EntityTypeCache.Read( entityType );
}
// Cache all the Field Types
foreach ( var fieldType in new Rock.Model.FieldTypeService( rockContext ).Queryable().AsNoTracking() )
{
Rock.Web.Cache.FieldTypeCache.Read( fieldType );
}
var all = Rock.Web.Cache.FieldTypeCache.All();
// Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached
var qualifiers = new Dictionary<int, Dictionary<string, string>>();
foreach ( var attributeQualifier in new Rock.Model.AttributeQualifierService( rockContext ).Queryable().AsNoTracking() )
{
try
{
if ( !qualifiers.ContainsKey( attributeQualifier.AttributeId ) )
{
qualifiers.Add( attributeQualifier.AttributeId, new Dictionary<string, string>() );
}
qualifiers[attributeQualifier.AttributeId].Add( attributeQualifier.Key, attributeQualifier.Value );
}
catch ( Exception ex )
{
LogError( ex, null );
}
}
// Cache all the attributes, except for user preferences
var attributeQuery = new Rock.Model.AttributeService( rockContext ).Queryable( "Categories" );
int? personUserValueEntityTypeId = Rock.Web.Cache.EntityTypeCache.GetId( Person.USER_VALUE_ENTITY );
if (personUserValueEntityTypeId.HasValue)
{
attributeQuery = attributeQuery.Where(a => !a.EntityTypeId.HasValue || a.EntityTypeId.Value != personUserValueEntityTypeId);
}
foreach ( var attribute in attributeQuery.AsNoTracking().ToList() )
{
if ( qualifiers.ContainsKey( attribute.Id ) )
Rock.Web.Cache.AttributeCache.Read( attribute, qualifiers[attribute.Id] );
else
Rock.Web.Cache.AttributeCache.Read( attribute, new Dictionary<string, string>() );
}
// cache all the Country Defined Values since those can be loaded in just a few millisecond here, but take around 1-2 seconds if first loaded when formatting an address
foreach ( var definedValue in new Rock.Model.DefinedValueService( rockContext ).GetByDefinedTypeGuid( Rock.SystemGuid.DefinedType.LOCATION_COUNTRIES.AsGuid() ).AsNoTracking() )
{
DefinedValueCache.Read( definedValue, rockContext );
}
}