/// <summary>
        /// Get the specified object
        /// </summary>
        internal override TModel Get(DataContext context, Guid key)
        {
            // We need to join, but to what?
            // True to get the cache item
            var cacheService = new AdoPersistenceCache(context);
            var cacheItem    = cacheService?.GetCacheItem <TModel>(key) as TModel;

            if (cacheItem != null && context.Transaction == null)
            {
                if (cacheItem.LoadState < context.LoadState)
                {
                    cacheItem.LoadAssociations(context);
                    cacheService?.Add(cacheItem);
                }
                return(cacheItem);
            }
            else
            {
                var domainQuery = this.m_settingsProvider.GetQueryBuilder().CreateQuery <TModel>(o => o.Key == key && o.ObsoletionTime == null).Build();
                domainQuery.OrderBy <TRootEntity>(o => o.VersionSequenceId, Core.Model.Map.SortOrderType.OrderByDescending);
                cacheItem = this.ToModelInstance(context.FirstOrDefault <TQueryReturn>(domainQuery), context);
                if (cacheService != null)
                {
                    cacheService.Add(cacheItem);
                }
                return(cacheItem);
            }
        }
Пример #2
0
        /// <summary>
        /// Tru to load from cache
        /// </summary>
        protected virtual TModel CacheConvert(Object o, DataContext context)
        {
            if (o == null)
            {
                return(null);
            }

            var cacheService = new AdoPersistenceCache(context);

            var idData  = (o as CompositeResult)?.Values.OfType <IDbIdentified>().FirstOrDefault() ?? o as IDbIdentified;
            var objData = (o as CompositeResult)?.Values.OfType <IDbBaseData>().FirstOrDefault() ?? o as IDbBaseData;

            if (objData?.ObsoletionTime != null || idData == null || idData.Key == Guid.Empty)
            {
                return(this.ToModelInstance(o, context));
            }
            else
            {
                var cacheItem = cacheService?.GetCacheItem <TModel>(idData?.Key ?? Guid.Empty);
                if (cacheItem != null)
                {
                    if (cacheItem.LoadState < context.LoadState)
                    {
                        cacheItem.LoadAssociations(context);
                        cacheService?.Add(cacheItem);
                    }
                    return(cacheItem);
                }
                else
                {
                    cacheItem = this.ToModelInstance(o, context);
                    if (context.Transaction == null)
                    {
                        cacheService?.Add(cacheItem);
                    }
                }
                return(cacheItem);
            }
        }