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


C# EntityManager.GetEntityByKey方法代码示例

本文整理汇总了C#中EntityManager.GetEntityByKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityManager.GetEntityByKey方法的具体用法?C# EntityManager.GetEntityByKey怎么用?C# EntityManager.GetEntityByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntityManager的用法示例。


在下文中一共展示了EntityManager.GetEntityByKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Resolve

    public EntityError Resolve(EntityManager em) {
      IsServerError = true;
      try {
        EntityType entityType = null;
        if (EntityTypeName != null) {
          var stName = TypeNameInfo.FromClrTypeName(EntityTypeName).ToClient(em.MetadataStore).StructuralTypeName;
          entityType = em.MetadataStore.GetEntityType(stName);
          var ek = new EntityKey(entityType, KeyValues);
          Entity = em.GetEntityByKey(ek);
        }

        
        if (entityType != null) {
          if (PropertyName != null) {
            Property = entityType.Properties.FirstOrDefault(p => p.NameOnServer == PropertyName);
            if (Property != null) {
              PropertyName = Property.Name;
            }
          }
          
          var vc = new ValidationContext(this.Entity);
          vc.Property = Property;
          var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? "");
          var ve = new ValidationError(null, vc, ErrorMessage, veKey);
          ve.IsServerError = true;
          this.Entity.EntityAspect.ValidationErrors.Add(ve);
        }
      } catch (Exception e) {
        ErrorMessage = ( ErrorMessage ?? "") + ":  Unable to Resolve this error: " + e.Message;
      }
      return this;
    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:32,代码来源:SaveException.cs

示例2: ProcessSaveResult

    private SaveResult ProcessSaveResult(EntityManager entityManager, SaveOptions saveOptions, JNode jNode) {

      var kms = jNode.GetArray<KeyMapping>("KeyMappings");
      var keyMappings = kms.Select(km => ToEntityKeys(km, entityManager.MetadataStore)).ToDictionary(tpl => tpl.Item1, tpl => tpl.Item2);
      using (entityManager.NewIsLoadingBlock(false)) {
        keyMappings.ForEach(km => {
          var targetEntity = entityManager.GetEntityByKey(km.Key);
          targetEntity.EntityAspect.SetDpValue(km.Key.EntityType.KeyProperties[0], km.Value.Values[0]);
        });

        var entityNodes = jNode.GetToken<JArray>("Entities");

        var serializer = new JsonSerializer();
        var mappingContext = new MappingContext() {
          EntityManager = entityManager,
          MergeStrategy = MergeStrategy.OverwriteChanges,
          LoadingOperation = LoadingOperation.Save,
          JsonResultsAdapter = saveOptions.DataService.JsonResultsAdapter
        };
        var jsonConverter = new JsonEntityConverter(mappingContext);
        serializer.Converters.Add(jsonConverter);
        // serializer.Converters.Add(new StringEnumConverter());
        // Don't use the result of the Deserialize call to get the list of entities 
        // because it won't include entities added on the server.
        serializer.Deserialize<IEnumerable<IEntity>>(entityNodes.CreateReader());
        var allEntities = mappingContext.Entities;
        allEntities.ForEach(e => e.EntityAspect.AcceptChanges());
        return new SaveResult(allEntities, keyMappings);
      }

    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:31,代码来源:DataServiceAdapter.WebApi.cs

示例3: ExpImpDeleted

    public async Task ExpImpDeleted() {
      var em1 = await TestFns.NewEm(_serviceName);

      var c1 = new Customer() { CompanyName = "Test_1", City = "Oakland", RowVersion = 13, Fax = "510 999-9999" };
      var c2 = new Customer() { CompanyName = "Test_2", City = "Oakland", RowVersion = 13, Fax = "510 999-9999" };
      em1.AddEntity(c1);
      em1.AddEntity(c2);
      var sr = await em1.SaveChanges();
      Assert.IsTrue(sr.Entities.Count == 2);
      c1.EntityAspect.Delete();
      c2.CompanyName = TestFns.MorphString(c2.CompanyName);
      var exportedEntities = em1.ExportEntities(null, false);
      var em2 = new EntityManager(em1);
      em2.ImportEntities(exportedEntities);
      var c1x = em2.GetEntityByKey<Customer>(c1.EntityAspect.EntityKey);
      Assert.IsTrue(c1x.EntityAspect.EntityState.IsDeleted(), "should be deleted");
      var c2x = em2.GetEntityByKey<Customer>(c2.EntityAspect.EntityKey);
      Assert.IsTrue(c2x.CompanyName == c2.CompanyName, "company names should match");
    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:19,代码来源:ExportImportTests.cs

示例4: ExpImpWithNulls

    public async Task ExpImpWithNulls() {
      var em1 = await TestFns.NewEm(_serviceName);

      var queryOptions = new QueryOptions(FetchStrategy.FromServer, MergeStrategy.OverwriteChanges);
      var q0 = new EntityQuery<Customer>().Where(c => c.CompanyName != null && c.City != null)
         .With(MergeStrategy.OverwriteChanges);
      var r0 = (await em1.ExecuteQuery(q0)).ToList();
      Assert.IsTrue(r0.Count > 2);
      r0[0].CompanyName = null;
      r0[1].City = null;
      var exportedEntities = em1.ExportEntities(null, false);
      var em2 = new EntityManager(em1);
      em2.ImportEntities(exportedEntities);
      var ek0 = r0[0].EntityAspect.EntityKey;
      var ek1 = r0[1].EntityAspect.EntityKey;
      var e0 = em2.GetEntityByKey<Customer>(ek0);
      Assert.IsTrue(e0.CompanyName == null, "company name should be null");
      Assert.IsTrue(e0.EntityAspect.EntityState.IsModified());
      var e1 = em2.GetEntityByKey<Customer>(ek1);
      Assert.IsTrue(e1.City == null, "city should be null");
      Assert.IsTrue(e1.EntityAspect.EntityState.IsModified());
      em2.AcceptChanges();
      var exportedEntities2 = em2.ExportEntities(null, false);
      em1.ImportEntities(exportedEntities2, new ImportOptions(MergeStrategy.OverwriteChanges));
      Assert.IsTrue(em1.GetChanges().Count() == 0);

    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:27,代码来源:ExportImportTests.cs


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