public void SaveObject(string persistenceId, string persistenceContext, string objectContent)
        {
            try
            {
                TransactionOptions opt = new TransactionOptions();
                //opt.IsolationLevel = IsolationLevel.Snapshot;
                opt.Timeout = TimeSpan.FromSeconds(3);

                using (Persistence db = new Persistence("Persistence.sdf"))
                {
                    var obj = (from po in db.PersistedObjects
                                where
                                (
                                    po.PersistenceID == persistenceId
                                    && (string.IsNullOrEmpty(persistenceContext) || string.Compare(persistenceContext, po.PersistenceContext, true) == 0)
                                )
                                select po);

                    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, opt))
                    {
                        if (obj != null && obj.Count() > 0)
                        {
                            db.PersistedObjects.DeleteAllOnSubmit(obj);
                            db.SubmitChanges();
                        }

                        PersistedObjects po = new PersistedObjects();
                        po.PersistenceID = persistenceId;
                        po.Content = objectContent;

                        po.PersistenceContext = string.IsNullOrEmpty(persistenceContext) ?
                            string.Empty : persistenceContext;

                        db.PersistedObjects.InsertOnSubmit(po);
                        db.SubmitChanges();

                        ts.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
Exemplo n.º 2
0
 partial void DeletePersistedObjects(PersistedObjects instance);
Exemplo n.º 3
0
 partial void UpdatePersistedObjects(PersistedObjects instance);
Exemplo n.º 4
0
 partial void InsertPersistedObjects(PersistedObjects instance);