当前位置: 首页>>代码示例>>C#>>正文


C# ElasticsearchContext.SaveChangesAsync方法代码示例

本文整理汇总了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]);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:36,代码来源:DefaultElasticsearchCRUDTests.cs

示例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);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:15,代码来源:DefaultElasticsearchCRUDTests.cs

示例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);
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:10,代码来源:DefaultElasticsearchCRUDTests.cs

示例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);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:19,代码来源:DefaultElasticsearchCRUDTests.cs

示例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);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:24,代码来源:DefaultElasticsearchCRUDTests.cs

示例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.
                    });
                }
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:29,代码来源:DefaultElasticsearchCRUDTests.cs

示例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);
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:10,代码来源:DefaultElasticsearchCRUDTests.cs


注:本文中的ElasticsearchContext.SaveChangesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。