Esempio n. 1
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);
            }
        }
Esempio n. 2
0
 public void Save(DataObject_Base data)
 {
     Save(data, OnConflictOption.Default);
 }