本文整理汇总了C#中ElasticsearchContext.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticsearchContext.SaveChangesAsync方法的具体用法?C# ElasticsearchContext.SaveChangesAsync怎么用?C# ElasticsearchContext.SaveChangesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElasticsearchContext
的用法示例。
在下文中一共展示了ElasticsearchContext.SaveChangesAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDefaultContextUpdateEntity
public void TestDefaultContextUpdateEntity()
{
const int entityId = 34;
SkillTestEntity resultfromGet;
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
// add a new entity
context.AddUpdateDocument(_entitiesForTests[entityId], entityId);
// Save to Elasticsearch
var ret = context.SaveChangesAsync();
Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
// Get the entity
resultfromGet = context.GetDocumentAsync<SkillTestEntity>(entityId).Result.PayloadResult;
}
resultfromGet.Name = "updated";
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
// update entity
context.AddUpdateDocument(resultfromGet, entityId);
// Save to Elasticsearch
var ret = context.SaveChangesAsync();
Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
// Get the entity
var readEntity = context.GetDocumentAsync<SkillTestEntity>(entityId).Result.PayloadResult;
Assert.AreEqual(readEntity.Name, resultfromGet.Name);
Assert.AreNotEqual(readEntity.Name, _entitiesForTests[entityId]);
}
}
示例2: TestDefaultContextAdd100Entities
public void TestDefaultContextAdd100Entities()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
for (int i = 0; i < 100; i++)
{
context.AddUpdateDocument(_entitiesForTests[i], i);
}
// Save to Elasticsearch
var ret = context.SaveChangesAsync();
Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
}
}
示例3: TestDefaultContextSaveWithNoChanges
public void TestDefaultContextSaveWithNoChanges()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
var entityResult = context.SaveChangesAsync();
entityResult.Wait();
Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.OK);
}
}
示例4: TestDefaultContextGetEntityAsync
public void TestDefaultContextGetEntityAsync()
{
const int entityId = 34;
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(_entitiesForTests[entityId], entityId);
// Save to Elasticsearch
var ret = context.SaveChangesAsync();
Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
// Get the entity
var entityResult = context.GetDocumentAsync<SkillTestEntity>(entityId);
Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.OK);
Assert.AreEqual(entityResult.Result.PayloadResult.Id, entityId);
Assert.IsNotNull(entityResult.Result.PayloadResult);
}
}
示例5: TestDefaultContextDeleteIndex
public void TestDefaultContextDeleteIndex()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
for (int i = 0; i < 100; i++)
{
context.AddUpdateDocument(_entitiesForTests[i], i);
}
// Save to Elasticsearch
var ret = context.SaveChangesAsync();
Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
}
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AllowDeleteForIndex = true;
var entityResult = context.DeleteIndexAsync<SkillTestEntityNoIndex>();
entityResult.Wait();
Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.NotFound);
}
}
示例6: TestDefaultContextDeleteEntityWhichDoesNotExist
public void TestDefaultContextDeleteEntityWhichDoesNotExist()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
// Delete the entity
context.DeleteDocument<SkillTestEntity>(6433);
context.DeleteDocument<SkillTestEntity>(22222);
var task = Task.Run(() => context.SaveChangesAsync());
try
{
task.Wait();
}
catch (AggregateException ae)
{
ae.Handle(x =>
{
if (x is ElasticsearchCrudException) // This is what we expect.
{
throw x;
}
return false; // stop.
});
}
}
}
示例7: TestDefaultContextAddEntitySaveChangesAsyncBadUrl
public void TestDefaultContextAddEntitySaveChangesAsyncBadUrl()
{
using (var context = new ElasticsearchContext("http://locaghghghlhost:9200/", _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(_entitiesForTests[1], 1);
var ret = context.SaveChangesAsync();
Console.WriteLine(ret.Result.Status);
}
}