本文整理汇总了C#中Database.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Delete方法的具体用法?C# Database.Delete怎么用?C# Database.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteEntities
protected override void DeleteEntities(List<Entity> entities)
{
using (var database = new Database("SQLiteTest"))
{
using (var transaction = database.GetTransaction())
{
entities.ForEach(entity => database.Delete(entity));
transaction.Complete();
}
}
}
示例2: DatabaseFetchesUpdatesAndDeletesWithQueries
public void DatabaseFetchesUpdatesAndDeletesWithQueries()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var ids = new List<int>();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
{
db.Load();
objs.ToList().ForEach(o => ids.Add(db.Add(o)));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
{
db.Load();
using (var t = db.BeginTransaction())
{
var last = db.SelectLast(s => true, 1).LastOrDefault();
Assert.IsNotNull(last);
db.Update(s => s.Value<string>("Name") == last.Name
, new System.Action<MockClassA>(a => a.Name = "last"));
db.Delete(s => true);
t.Commit();
}
var selected = db.Select(s => true);
Assert.AreEqual(0, selected.Count);
}
using (var db = new Database<int, MockClassA>(_testName + ".database", new JSONFormatter()))
{
db.Load();
var selected = db.Select(s => true);
Assert.AreEqual(0, selected.Count);
}
}
}
示例3: CryptoSerializesQueries
public void CryptoSerializesQueries()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var key = new SecureString();
var vec = new SecureString();
for (var i = 0; i <= 25; i++)
{
key.AppendChar((char)(((i + 25763) * i * Math.PI) % char.MaxValue));
vec.AppendChar((char)(((i + 41359) * i * Math.PI) % char.MaxValue));
}
var objects = new List<ResourceContainer>()
{
new Mocks.MockImageContainer(testRes.Luna_DIFF) { Name = "Luna_DIFF"},
new Mocks.MockImageContainer(testRes.Luna_MAT) { Name = "Luna_MAT"},
new Mocks.MockImageContainer(testRes.Luna_NRM) { Name = "Luna_NRM"}
};
using (var db = new Database<string, ResourceContainer>
(_testName + ".database", "Name", new FileCore<string, long>(new SeedString(255), new Seed64()),
new BinConverterString(),
new QueryCryptoFormatter(new RC2Crypto(vec), new BSONFormatter(), key)))
{
db.Load();
using (var t = db.BeginTransaction())
{
foreach (var o in objects)
o.Name = db.Add(o);
t.Commit();
}
var dmm = DynamicMemberManager.GetManager(db);
Assert.AreEqual(3, dmm._primaryIndex.Length);
using (var t = db.BeginTransaction())
{
foreach (var o in objects)
db.Update(o, o.Name);
t.Commit();
}
Assert.AreEqual(3, dmm._primaryIndex.Length);
}
using (var db = new Database<string, ResourceContainer>
(_testName + ".database", new QueryCryptoFormatter(new RC2Crypto(vec), new BSONFormatter(), key)))
{
db.Load();
using (var t = db.BeginTransaction())
{
db.Delete("Luna_MAT");
t.Commit();
}
Assert.IsNull(db.Fetch("Luna_MAT"));
var o = db.Select(s => true);
Assert.AreEqual(2, o.Count);
}
}
示例4: FullEnlistmentScopeCommitsTest
public void FullEnlistmentScopeCommitsTest()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objects = TestResourceFactory.GetMockClassAObjects(12);
ITransaction trans = null;
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
{
db.Load();
using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
{
trans = db.BeginTransaction();
foreach (var obj in objects)
obj.Id = db.AddOrUpdate(obj, 0);
var update = db.Fetch(3);
update.Name = "Updated " + update.Id;
db.AddOrUpdate(update, update.Id);
db.Delete(objects.Last().Id);
scope.Complete();
}
while (!trans.IsComplete)
Thread.Sleep(100);
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
{
db.Load();
using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
{
trans = db.BeginTransaction();
db.Update<MockClassA>(u => !u.Value<string>("Name").Contains("Updated"), m => m.Name = "batch " + m.Id);
var old = db.Select(s => s.Value<string>("Name").Contains("Updated"));
Assert.AreEqual(1, old.Count);
Assert.AreEqual("Updated 3", old.Single().Name);
var updates = db.SelectFirst(s => s.Value<string>("Name").Contains("batch"), 11);
Assert.AreEqual(10, updates.Count);
Assert.AreEqual(1, updates.First().Id);
Assert.AreEqual(11, updates.Last().Id);
scope.Complete();
}
while (!trans.IsComplete)
Thread.Sleep(100);
}
}
}
示例5: SinglePhaseScopeRollsBackTest
public void SinglePhaseScopeRollsBackTest()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objects = TestResourceFactory.GetMockClassAObjects(12);
ITransaction trans = null;
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.SinglePhasePromotable }))
{
db.Load();
using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
{
trans = db.BeginTransaction();
foreach (var obj in objects)
obj.Id = db.AddOrUpdate(obj, 0);
var update = db.Fetch(3);
update.Name = "Updated " + update.Id;
db.AddOrUpdate(update, update.Id);
db.Delete(objects.Last().Id);
}
while (!trans.IsComplete)
Thread.Sleep(100);
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.SinglePhasePromotable }))
{
db.Load();
Assert.AreEqual(0, db.Length);
}
}
}
示例6: FullEnlistmentScopeRollsBackOnExceptionTest
public void FullEnlistmentScopeRollsBackOnExceptionTest()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objects = TestResourceFactory.GetMockClassAObjects(12);
ITransaction trans = null;
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
{
db.Load();
try
{
using (var scope = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew))
{
using (trans = db.BeginTransaction())
{
foreach (var obj in objects)
obj.Id = db.AddOrUpdate(obj, 0);
var update = db.Fetch(3);
update.Name = "Updated " + update.Id;
db.AddOrUpdate(update, update.Id);
db.Delete(objects.Last().Id);
throw new Exception();
}
}
}
catch (Exception) { }
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new BSONFormatter(),
new TransactionManager<int, MockClassA>() { DistributedScopeEnlistment = TransactionEnlistmentType.FullEnlistmentNotification }))
{
db.Load();
Assert.AreEqual(0, db.Length);
}
}
}
示例7: PubSubNeverPicksUpOwnTransactions
public void PubSubNeverPicksUpOwnTransactions()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var pdb1 = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID", new FileCore<Guid, long>())
.WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName)))
.WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
{
pdb1.Load();
pdb1.Clear();
using (var t = pdb1.BeginTransaction())
{
pdb1.Delete(o => o != null);
t.Commit();
}
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
var negativeObjects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
using (var t = pdb1.BeginTransaction())
{
objects.ForEach(o => pdb1.Add(o));
t.Commit();
}
var testTran = new MockTransaction<Guid, MockClassA>(
new TransactionManager<Guid, MockClassA>(
new MockTransactionFactory<Guid, MockClassA>()
, new TransactionSynchronizer<Guid, MockClassA>()));
testTran.Source = pdb1.TransactionSource;
foreach (var no in negativeObjects)
testTran.Enlist(Action.Create, no.ReplicationID, (MockClassA)no);
testTran.Commit();
var formatter = new BSONFormatter();
using (var fs = new FileStream(
Path.Combine(Environment.CurrentDirectory, _testName, testTran.Id.ToString() + ".trans")
, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, false))
{
var s = formatter.FormatObjStream(testTran);
s.WriteAllTo(fs);
fs.Flush();
fs.Close();
}
Thread.Sleep(750);
var sw = new Stopwatch();
sw.Start();
while (pdb1.FileFlushQueueActive && sw.ElapsedMilliseconds < 3000)
Thread.Sleep(100);
Assert.AreEqual(25, pdb1.Length);
}
}
}
示例8: IndexModule
//.........这里部分代码省略.........
};
/// <summary>
/// Update a specific site
/// </summary>
Put["/sites/{siteId}"] = parameter =>
{
string Id = parameter.siteId;
Sites snapshot = db.FetchBy<Sites>(sql => sql.Where(x => x.SiteId == Id)).FirstOrDefault();
Sites site = this.Bind<Sites>();
// Don't clear out fields existing fields.
site.Active = snapshot.Active;
site.DateTime = snapshot.DateTime;
site.MetaTitle = snapshot.MetaTitle;
site.MetaDescription = snapshot.MetaDescription;
site.MetaKeywords = snapshot.MetaKeywords;
db.Update(site);
db.Dispose();
string TagsPost = Request.Form.Tags.Value;
List<string> Tags = TagsPost.ToLower().Split(',').Select(s => s.Trim()).ToList();
List<Tags> AllTags = db.Fetch<Tags>();
db.Dispose();
List<string> AllTagNames = AllTags.Select(tn => tn.TagName).ToList();
//Delete all existing Tags for current site before linking up any new tags
db.Delete<SiteTags>("where SiteId = @0", Id);
db.Dispose();
foreach (string tag in Tags)
{
if (!AllTagNames.Contains(tag))
{
Tags newTag = new Tags();
newTag.TagId = ShortGuid.NewGuid().ToString();
newTag.TagName = tag;
newTag.Active = true;
db.Insert(newTag);
db.Dispose();
SiteTags newSiteTag = new SiteTags();
newSiteTag.SiteId = site.SiteId;
newSiteTag.TagId = newTag.TagId;
db.Insert(newSiteTag);
db.Dispose();
}
else
{
try
{
var ExistingTag = db.FetchBy<Tags>(sql => sql.Where(x => x.TagName == tag)).FirstOrDefault();
SiteTags newSiteTag = new SiteTags();
newSiteTag.SiteId = site.SiteId;
newSiteTag.TagId = ExistingTag.TagId;
示例9: DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex
public void DatabaseFetchesUpdatesAndDeletesWithSecondaryIndex()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var seed = new Seed32();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var ids = new List<int>();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
objs.ToList().ForEach(o => ids.Add(db.Add(o)));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
last.Name = "last";
db.Update(last, last.Id);
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
Assert.AreEqual("last", last.Name);
Assert.IsNotNull(db.Fetch(objs.First().Id));
db.Delete(objs.First().Id);
Assert.IsNull(db.Fetch(objs.First().Id));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
Assert.IsNull(db.Fetch(objs.First().Id));
db.Clear();
}
}
示例10: SecondaryIndexDeletesByIdAndByQuery
public void SecondaryIndexDeletesByIdAndByQuery()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objs = TestResourceFactory.GetMockClassAObjects(2500);
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
using (var t = db.BeginTransaction())
{
foreach (var o in objs)
o.Id = db.Add(o);
t.Commit();
}
db.Flush();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
var delete1 = objs.Skip(500).Take(500);
var delete2 = objs.Skip(1000).Take(500);
using (var t = db.BeginTransaction())
{
foreach (var o in delete1)
db.Delete(o.Id);
t.Commit();
}
while (db.FileFlushQueueActive)
Thread.Sleep(100);
Assert.IsNull(db.Fetch(delete1.First().Id));
using (var t = db.BeginTransaction())
{
Assert.AreEqual(500, db.Delete(f => delete2.Any(a => a.Id == f.Value<int>("Id"))));
t.Commit();
}
while (db.FileFlushQueueActive)
Thread.Sleep(100);
Assert.IsNull(db.Fetch(delete2.First().Id));
Assert.AreEqual(1500, db.Select(s => true).Count());
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
db.Reorganize();
Assert.AreEqual(1500, db.Select(s => true).Count());
}
}
示例11: DatabaseUpdatesIdFieldAndIndexes
public void DatabaseUpdatesIdFieldAndIndexes()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var ids = new List<int>();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
objs.ToList().ForEach(o => ids.Add(db.Add(o)));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
var oldId = last.Id;
last.Name = "last";
last.Id = 1024;
db.Update(last, oldId);
last = db.Fetch(last.Id);
Assert.AreEqual(1024, last.Id);
var old = db.Fetch(oldId);
Assert.IsNull(old);
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNull(last);
last = db.Fetch(1024);
Assert.IsNotNull(last);
Assert.AreEqual("last", last.Name);
Assert.IsNotNull(db.Fetch(objs.First().Id));
db.Delete(new int[] { objs.First().Id, objs.Last().Id });
Assert.IsNull(db.Fetch(objs.First().Id));
Assert.IsNull(db.Fetch(objs.Last().Id));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
Assert.IsNull(db.Fetch(objs.First().Id));
db.Clear();
}
}
}
示例12: DatabaseFetchesUpdatesAndDeletes
public void DatabaseFetchesUpdatesAndDeletes()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
objs.ToList().ForEach(o => o.Id = db.Add(o));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
last.Name = "last";
db.Update(last);
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
Assert.AreEqual("last", last.Name);
Assert.IsNotNull(db.Fetch(objs.First().Id));
db.Delete(objs.First().Id);
Assert.IsNull(db.Fetch(objs.First().Id));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
Assert.IsNull(db.Fetch(objs.First().Id));
db.Clear();
}
}
}
示例13: RecreateFilters
public void RecreateFilters(string objectName, string filterName, List<Frapid.Config.Entities.Filter> filters)
{
if (!this.SkipValidation)
{
if (!this.Validated)
{
this.Validate(AccessTypeEnum.Create, this._LoginId, this._Catalog, false);
}
if (!this.HasAccess)
{
Log.Information("Access to add entity \"Filter\" was denied to the user with Login ID {LoginId}. {filters}", this._LoginId, filters);
throw new UnauthorizedException("Access is denied.");
}
}
using (Database db = new Database(ConnectionString.GetConnectionString(this._Catalog), Factory.ProviderName))
{
using (ITransaction transaction = db.GetTransaction())
{
var toDelete = this.GetWhere(1, new List<Frapid.DataAccess.Models.Filter>
{
new Frapid.DataAccess.Models.Filter { ColumnName = "object_name", FilterCondition = (int) FilterCondition.IsEqualTo, FilterValue = objectName },
new Frapid.DataAccess.Models.Filter { ColumnName = "filter_name", FilterCondition = (int) FilterCondition.IsEqualTo, FilterValue = filterName }
});
foreach (var filter in toDelete)
{
db.Delete(filter);
}
foreach (var filter in filters)
{
filter.AuditUserId = this._UserId;
filter.AuditTs = System.DateTime.UtcNow;
db.Insert(filter);
}
transaction.Complete();
}
}
}
示例14: TransactionResolvesDuplicateActions
public void TransactionResolvesDuplicateActions()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objects = TestResourceFactory.GetMockClassAObjects(12);
using (var fLock = new ManagedFileLock(_testName + ".database"))
{
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
using (var t = db.BeginTransaction())
{
objects.ToList().ForEach(o => o.Id = db.Add(o));
db.Update(objects[1], objects[1].Id);
t.Commit();
}
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
using (var t = db.BeginTransaction())
{
db.Update<MockClassA>(s => s.Value<int>("Id") == objects[2].Id, a => a.Name = a.Name + " updated");
db.Delete(objects[2].Id);
t.Commit();
}
}
}
}
示例15: TransactionFailsWhenUpdatingDeletedRecord
public void TransactionFailsWhenUpdatingDeletedRecord()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objects = TestResourceFactory.GetMockClassAObjects(12);
using (var fLock = new ManagedFileLock(_testName + ".database"))
{
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
db.BeginTransaction();
foreach (var obj in objects)
db.AddOrUpdate(obj, 0);
var update = db.Fetch(3);
update.Name = "Updated " + update.Id;
db.AddOrUpdate(update, update.Id);
db.Flush();
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
db.BeginTransaction();
db.Delete(d => d.Value<string>("Name").Contains("Updated"));
db.Update<MockClassA>(u => u.Value<string>("Name").Contains("Updated"), m => m.Name = "Should Fail " + m.Id);
db.Flush();
}
}
}