本文整理汇总了C#中MongoRepository.Save方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.Save方法的具体用法?C# MongoRepository.Save怎么用?C# MongoRepository.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoRepository
的用法示例。
在下文中一共展示了MongoRepository.Save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInsert
public void TestInsert()
{
var t = new Team {Name = "Test"};
var repo = new MongoRepository<Team>(_db);
repo.Save(t);
Assert.NotNull(t.Id);
}
示例2: TestRepository
public void TestRepository()
{
var teams = new List<Team> { new Team("Tom", false, 1), new Team("Olive", false, 2) };
var repo = new MongoRepository<Team>(_db);
foreach (var t in teams)
{
repo.Save(t);
}
var teamsRefresh = repo.QueryAll();
Assert.AreEqual(2 , teamsRefresh.Count());
}
示例3: Main
static void Main(string[] args)
{
var personReadModel = new MongoRepository<PersonDTO>("mongodb://localhost", "DDD_Light_MongoEventStore_Example", "Person_ReadModel");
EventStore.Instance.Configure(new MongoRepository<AggregateEvent>("mongodb://localhost", "DDD_Light_MongoEventStore_Example", "EventStore"), new JsonEventSerializationStrategy());
EventBus.Instance.Configure(EventStore.Instance, new JsonEventSerializationStrategy(), false);
EventBus.Instance.Subscribe((PersonCreated personCreated) =>
{
var personDTO = new PersonDTO {Id = personCreated.Id};
personReadModel.Save(personDTO);
});
EventBus.Instance.Subscribe((PersonNamed personNamed) =>
{
var personDTO = personReadModel.GetById(personNamed.PersonId);
personDTO.Name = personNamed.Name;
personDTO.WasRenamed = false;
personReadModel.Save(personDTO);
});
EventBus.Instance.Subscribe((PersonRenamed personRenamed) =>
{
var personDTO = personReadModel.GetById(personRenamed.PersonId);
personDTO.Name = personRenamed.Name;
personDTO.WasRenamed = true;
personReadModel.Save(personDTO);
});
NamePerson(personReadModel);
NameAndRenamePerson(personReadModel);
// Drop readmodel on mongo and then run this to restore
//EventBus.Instance.RestoreReadModel(EventBus.Instance);
Console.ReadLine();
}
示例4: TestGetById
public void TestGetById()
{
var repo = new MongoRepository<Team>(_db);
var team = new Team()
{
Name = "Tom"
};
repo.Save(team);
var id = team.Id;
var teamRefresh = repo.Find(id);
Assert.AreEqual(teamRefresh.Name, "Tom");
}
示例5: Save_IfHaveTheSameRecord_ReturnNull
public void Save_IfHaveTheSameRecord_ReturnNull()
{
var repository = new MongoRepository<TestModel>();
repository.Drop();
var item = TestModel.CreateInstance();
repository.Insert(item);
repository.Insert(new TestModel { StringValue = "sinan" });
item.StringValue = "sinan";
var res3 = repository.Save(item);
Assert.IsNull(res3);
}
示例6: Save_IfDontHaveTheSameRecord_ReturnItem
public void Save_IfDontHaveTheSameRecord_ReturnItem()
{
var repository = new MongoRepository<TestModel>();
repository.Drop();
var item = TestModel.CreateInstance();
var res = repository.Insert(item);
item.StringValue2 = "sinan";
var res2 = repository.Save(item);
Assert.IsNotNull(res2);
}
示例7: SaveRoom
public static bool SaveRoom(Room room)
{
if (VerifyRoom(room))
{
var mongoRepository = new MongoRepository<Room>(ConnectionString);
mongoRepository.Save(room);
return true;
}
return false;
}