本文整理汇总了C#中MongoRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.Delete方法的具体用法?C# MongoRepository.Delete怎么用?C# MongoRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoRepository
的用法示例。
在下文中一共展示了MongoRepository.Delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchTest
public void BatchTest()
{
IRepository<Customer> _customerRepo = new MongoRepository<Customer>();
var custlist = new List<Customer>(new Customer[] {
new Customer() { FirstName = "Customer A" },
new Customer() { FirstName = "Client B" },
new Customer() { FirstName = "Customer C" },
new Customer() { FirstName = "Client D" },
new Customer() { FirstName = "Customer E" },
new Customer() { FirstName = "Client F" },
new Customer() { FirstName = "Customer G" },
});
//Insert batch
_customerRepo.Add(custlist);
var count = _customerRepo.Count();
Assert.AreEqual(7, count);
foreach (Customer c in custlist)
Assert.AreNotEqual(new string('0', 24), c.Id);
//Update batch
foreach (Customer c in custlist)
c.LastName = c.FirstName;
_customerRepo.Update(custlist);
foreach (Customer c in _customerRepo)
Assert.AreEqual(c.FirstName, c.LastName);
//Delete by criteria
_customerRepo.Delete(f => f.FirstName.StartsWith("Client"));
count = _customerRepo.Count();
Assert.AreEqual(4, count);
//Delete specific object
_customerRepo.Delete(custlist[0]);
//Test AsQueryable
var selectedcustomers = from cust in _customerRepo
where cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")
select cust;
Assert.AreEqual(2, selectedcustomers.ToList().Count);
count = _customerRepo.Count();
Assert.AreEqual(3, count);
//Drop entire repo
new MongoRepositoryManager<Customer>().Drop();
count = _customerRepo.Count();
Assert.AreEqual(0, count);
}
示例2: CustomIDTypeTest
public void CustomIDTypeTest()
{
var xint = new MongoRepository<IntCustomer, int>();
xint.Add(new IntCustomer() { Id = 1, Name = "Test A" });
xint.Add(new IntCustomer() { Id = 2, Name = "Test B" });
var yint = xint.GetById(2);
Assert.AreEqual(yint.Name, "Test B");
xint.Delete(2);
Assert.AreEqual(1, xint.Count());
}
示例3: CustomIDTest
public void CustomIDTest()
{
var x = new MongoRepository<CustomIDEntity>();
var xm = new MongoRepositoryManager<CustomIDEntity>();
x.Add(new CustomIDEntity() { Id = "aaa" });
Assert.IsTrue(xm.Exists);
Assert.IsInstanceOfType(x.GetById("aaa"), typeof(CustomIDEntity));
Assert.AreEqual("aaa", x.GetById("aaa").Id);
x.Delete("aaa");
Assert.AreEqual(0, x.Count());
var y = new MongoRepository<CustomIDEntityCustomCollection>();
var ym = new MongoRepositoryManager<CustomIDEntityCustomCollection>();
y.Add(new CustomIDEntityCustomCollection() { Id = "xyz" });
Assert.IsTrue(ym.Exists);
Assert.AreEqual(ym.Name, "MyTestCollection");
Assert.AreEqual(y.CollectionName, "MyTestCollection");
Assert.IsInstanceOfType(y.GetById("xyz"), typeof(CustomIDEntityCustomCollection));
y.Delete("xyz");
Assert.AreEqual(0, y.Count());
}
示例4: RepositoryDeleteTest
public void RepositoryDeleteTest()
{
var target = new MongoContext();
var repository = new MongoRepository<Employee>(target);
Employee employee = null;
Yekzen.QualityTools.UnitTest.ExceptionAssert.InconclusiveWhenThrows<UnreachableException>(() => { employee = InsertInternal(repository); });
if(string.IsNullOrEmpty(employee.Id))
Assert.Inconclusive("Insert failed.");
repository.Delete(p => p.Id == employee.Id);
employee = repository.Single(p => p.Id == employee.Id);
Assert.IsNull(employee);
}
示例5: LoadOrCreateDummy
public static ParameterSet LoadOrCreateDummy()
{
var repo = new MongoRepository<ParameterSet>();
var defaultName = "DEFAULT";
var ps = repo.FirstOrDefault(p => p.Name == defaultName);
if (ps != null)
{
repo.Delete(ps);
}
ps = new ParameterSet
{
Name = defaultName,
Parameters = new List<Parameter>
{
new Parameter()
{
Name = "Server-ID",
TagId = ParameterTagId.ServerId,
IsActive = true,
IsAutoIncrement = true,
IsWriteOnly = false,
IsPartOfMatrixCode = true,
TargetValue = "0A-01-44-5A-47-01-02-62-5A-17",
ObisCode = RegisterIds.DeviceId.ToHexString("-")
},
new Parameter()
{
Name = "Hersteller Seriennummer",
TagId = ParameterTagId.ManufacturerSerialNumber,
IsActive = true,
IsAutoIncrement = false,
TargetValue = "", // derived from serverId
ObisCode = VendorSpecificRegisterIds.ManufacturerSerialNumber.ToHexString("-")
},
new Parameter()
{
Name = "Reallin Barcode",
TagId = ParameterTagId.PcbBarCode,
ObisCode = "",
IsNameplateOnly = true,
TargetValue = ""
},
new Parameter()
{
Name = "Messbetriebsart",
TagId = ParameterTagId.MeasurementMode,
IsActive = true,
TargetValue = "MM2",
ObisCode = VendorSpecificRegisterIds.MeasurementMode.ToHexString("-")
},
new Parameter()
{
Name="ECC Schlüssel generieren",
TagId = ParameterTagId.GenerateKeys,
IsActive = true,
TargetValue = "True",
ObisCode = VendorSpecificRegisterIds.GenerateKeys.ToHexString("-"),
IsWriteOnly = true
},
new Parameter()
{
Name = "ECC Public Key",
TagId = ParameterTagId.PublicKey,
IsActive = true,
IsReadOnly = true,
IsPartOfMatrixCode = true,
TargetValue = "",
ObisCode = RegisterIds.PublicKeySignature.ToHexString("-")
},
new Parameter()
{
Name = "Initialer AES Key M",
TagId = ParameterTagId.InitialKeyM,
IsActive = true,
IsRandomTargetValue = true,
TargetValue = "",
ObisCode = RegisterIds.SymmetricInitialKey.ToHexString("-")
},
new Parameter()
{
Name = "Grid Option",
TagId = ParameterTagId.GridOption,
IsActive = true,
TargetValue = "True",
ObisCode = RegisterIds.GridOptionEnabled.ToHexString("-")
},
new Parameter()
{
Name = "Tariff Option",
TagId = ParameterTagId.TarifOptionActive,
IsActive = true,
TargetValue = "True",
ObisCode = RegisterIds.TariffOptionEnabled.ToHexString("-")
},
new Parameter()
{
Name = "Tariff Configuration",
TagId = ParameterTagId.InverseTariffControl,
ObisCode = ObisEdl.DzgTerminalControlReverse.ToHexString("-"),
//.........这里部分代码省略.........
示例6: DeleteRoom
public static void DeleteRoom(Room room)
{
var mongoRepository = new MongoRepository<Room>(ConnectionString);
mongoRepository.Delete(room);
}