Esempio n. 1
0
        public static EfMapping GetMappingsForContext(DbContext context)
        {
            var type = context.GetType();

            if (!cache.TryGetValue(type, out EfMapping mapping))
            {
                mapping = new EfMapping(context);
                cache.Add(type, mapping);
            }
            return(mapping);
        }
Esempio n. 2
0
        public static EfMapping GetMappingsForContext(DbContext context, bool ignoreCache = false)
        {
            var       type = context.GetType();
            EfMapping mapping;

            if (ignoreCache)
            {
                mapping = new EfMapping(context);
            }
            else if (!cache.TryGetValue(type, out mapping))
            {
                mapping = new EfMapping(context);
                cache.Add(type, mapping);
            }
            return(mapping);
        }
        public static EfMapping GetMappingsForContext(DbContext context)
        {
            var       type = context.GetType();
            EfMapping mapping;

            if (!cache.TryGetValue(type, out mapping))
            {
                //lock only if we don't have the item in the cache
                lock (cache)
                {
                    if (!cache.TryGetValue(type, out mapping))
                    {
                        mapping = new EfMapping(context);
                        cache.Add(type, mapping);
                    }
                }
            }
            return(mapping);
        }
 public static EfMapping GetMappingsForContext(DbContext context)
 {
     var type = context.GetType();
     EfMapping mapping;
     if (!cache.TryGetValue(type, out mapping))
     {
         mapping = new EfMapping(context);
         cache.Add(type, mapping);
     }
     return mapping;
 }
        public static EfMapping GetMappingsForContext(DbContext context)
        {
            var type = context.GetType();

            EfMapping mapping;

            //Try our cache lookup.  If we find an item in the cache
            //there is no reason to obtain a lock and limit this part 
            //of the code to a single thread
            if (!cache.TryGetValue(type, out mapping))
            {
                //if the cache lookup fails lock so only a single thread
                //at a time can access the add code
                lock (lckObj)
                {
                    //Check the cache again.  If 2 threads failed the first cache lookup
                    //the first thread will add the item to the cache
                    //the second thread will wait on the lock and then pull the item from
                    //cache.
                    if (!cache.TryGetValue(type, out mapping))
                    {
                        mapping = new EfMapping(context);
                        cache.Add(type, mapping);
                    }
                }
            }

            return mapping;
        }