Esempio n. 1
0
        public virtual OperationResult Upsert(ICollection <TModel> items)
        {
            _connectionProvider.WaitOne();
            OperationResult result;

            try
            {
                foreach (var item in items)
                {
                    item.LastTimeSynced = DateTime.UtcNow;
                }

                var objIds =
                    items.Select(i => (object)i.Id)
                    .ToList();
                Connection.RunInTransaction(() =>
                {
                    Connection.DeleteAll(items, recursive: true);
                    Connection.InsertAllWithChildren(items, recursive: true);
                });
                OnReplaceComplete(items);
                result = OperationResult.CreateSuccessResult();
            }
            catch (Exception ex)
            {
                result = OperationResult.CreateFailure(ex);
            }
            finally
            {
                _connectionProvider.Release();
            }
            return(result);
        }
Esempio n. 2
0
        public virtual void Upsert(ICollection <TModel> items)
        {
            var objIds =
                items.Select(i => (object)i.Id)
                .ToList();

            _connectionProvider.WaitOne();
            try
            {
                Connection.RunInTransaction(() =>
                {
                    Connection.DeleteAllIds <TModel>(objIds);
                    Connection.InsertAllWithChildren(items, recursive: true);
                });
            }
            finally
            {
                _connectionProvider.Release();
            }
            OnReplaceComplete(items);
        }