Ejemplo n.º 1
0
 internal static FastProperty[] CachePropsManager(this Type type)
 {
     if (!EntityCache.ContainsKey(type.FullName))
     {
         EntityCache.Add(type.FullName, EnumerableProp(type).ToArray());
     }
     return(EntityCache[type.FullName]);
 }
Ejemplo n.º 2
0
        public void Save(DataObject_Base data, OnConflictOption option, bool cache = true)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (data.IsChanged == false)
            {
                Logger.Log("save skipped because data has no changes", LogCategory.CRUD, LogLevel.Verbose);
                return;
            }

            if (!data.IsPersisted)
            {
                object primaryKey = Insert(data, option: option);

                var dal = data.DAL;
                if (dal != this)
                {
                    data.InternalSetDAL(this);
                }

                if (cache && primaryKey != null)
                {
                    EntityCache cacheStore = GetEntityCache(data.GetType());

                    Debug.Assert(cacheStore.ContainsKey(primaryKey) == false, "Cache already contains entity, existing entity will be replaced");
                    if (cacheStore.ContainsKey(primaryKey))
                    {
                        cacheStore[primaryKey] = data;
                    }
                    else
                    {
                        cacheStore.Add(primaryKey, data);
                    }
                }
            }
            else
            {
                Update(data, option: option);
            }
        }