Example #1
0
        protected async Task <IList <PostStoreEntityId> > DoDeleteEntitiesList(IEsentSession session, IEnumerable <PostStoreEntityId> toDelete)
        {
            var result = new List <PostStoreEntityId>();

            async Task Delete(PostStoreEntityId[] toDeletePart)
            {
                await session.RunInTransaction(() =>
                {
                    using (var table = OpenPostsTable(session, OpenTableGrbit.None))
                    {
                        using (var accTable = OpenAccessLogTable(session, OpenTableGrbit.None))
                        {
                            using (var mediaTable = OpenMediaFilesTable(session, OpenTableGrbit.None))
                            {
                                foreach (var id in toDeletePart)
                                {
                                    if (table.Indexes.PrimaryIndex.Find(table.Indexes.PrimaryIndex.CreateKey(id.Id)))
                                    {
                                        table.DeleteCurrentRow();
                                        result.Add(id);
                                    }
                                    accTable.Indexes.EntityIdIndex.SetAsCurrentIndex();
                                    foreach (var _ in accTable.Indexes.EntityIdIndex.Enumerate(accTable.Indexes.EntityIdIndex.CreateKey(id.Id)))
                                    {
                                        accTable.DeleteCurrentRow();
                                    }
                                    mediaTable.Indexes.EntityReferencesIndex.SetAsCurrentIndex();
                                    foreach (var _ in mediaTable.Indexes.EntityReferencesIndex.Enumerate(mediaTable.Indexes.EntityReferencesIndex.CreateKey(id.Id)))
                                    {
                                        mediaTable.DeleteCurrentRow();
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }, 1);
            }

            var split = toDelete.SplitSet(20).Select(s => s.ToArray());

            foreach (var part in split)
            {
                await Delete(part);
            }
            return(result);
        }
Example #2
0
 private ValueTask <Nothing> EnsureTableversion(IEsentSession session)
 {
     return(session.RunInTransaction(() =>
     {
         var sid = session.Session;
         var dbid = session.Database;
         JET_TABLEID tvid;
         if (Api.TryOpenTable(sid, dbid, TableVersionTable, OpenTableGrbit.ReadOnly, out tvid))
         {
             Api.JetCloseTable(sid, tvid);
             return false;
         }
         Api.JetCreateTable(sid, dbid, TableVersionTable, 1, 100, out tvid);
         try
         {
             JET_COLUMNID colid, colval;
             Api.JetAddColumn(sid, tvid, TableVersionIdColumn, new JET_COLUMNDEF()
             {
                 coltyp = JET_coltyp.Text,
                 cbMax = 125,
                 grbit = ColumndefGrbit.ColumnNotNULL,
                 cp = JET_CP.Unicode
             }, null, 0, out colid);
             Api.JetAddColumn(sid, tvid, TableVersionVersionColumn, new JET_COLUMNDEF()
             {
                 coltyp = JET_coltyp.Long,
                 grbit = ColumndefGrbit.ColumnNotNULL
             }, null, 0, out colval);
             var indexDef = $"+{TableVersionIdColumn}\0\0";
             Api.JetCreateIndex(sid, tvid, TableVersionPkIndex, CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique, indexDef, indexDef.Length, 100);
             return true;
         }
         finally
         {
             Api.JetCloseTable(sid, tvid);
         }
     }));
 }