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


C# EntityManager.FetchMetadata方法代码示例

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


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

示例1: CanGetMetadata

    public async Task CanGetMetadata() {

      // Confirm the metadata can be fetched from the server
      var entityManager = new EntityManager(_serviceName);
      var dataService = await entityManager.FetchMetadata();
      Assert.IsNotNull(dataService);
    }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:7,代码来源:QueryTests.cs

示例2: QueryRoles

        public async Task QueryRoles()
        {
            //Assert.Inconclusive("See comments in the QueryRoles test");

            // Issues:
            //
            // 1.  When the RoleType column was not present in the Role entity in the database (NorthwindIB.sdf), 
            //     the query failed with "Internal Server Error".  A more explanatory message would be nice.  
            //     The RoleType column has been added (nullable int), so this error no longer occurs.
            //
            // 2.  Comment out the RoleType property in the client model (Model.cs in Client\Model_Northwind.Sharp project lines 514-517).
            //     In this case, the client throws a null reference exception in CsdlMetadataProcessor.cs.
            //     This is the FIRST problem reported by the user.  A more informative message would be helpful.
            //
            // Note that this condition causes many other tests to fail as well.
            //
            // 3.  Uncomment the RoleType property in the client model.  Then the client throws in JsonEntityConverter.cs.
            //     This is the SECOND problem reported by the user.  This looks like a genuine bug that should be fixed.
            //

            var manager = new EntityManager(_serviceName);
                // Metadata must be fetched before CreateEntity() can be called
                await manager.FetchMetadata();

                var query = new EntityQuery<Role>();
                var allRoles = await manager.ExecuteQuery(query);

                Assert.IsTrue(allRoles.Any(), "There should be some roles defined");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:29,代码来源:QueryDatatypeTests.cs

示例3: ParallelQueries

        public async Task ParallelQueries() {
            var entityManager = new EntityManager(_serviceName);
            await entityManager.FetchMetadata();
            var idQuery = new EntityQuery<Customer>();
            var entities = await entityManager.ExecuteQuery(idQuery);

            var n = 20;
            var ids = entities.Select(c => c.CustomerID).Take(n).ToArray();

            // In case there aren't n customers available
            var actualCustomers = ids.Count();
            var numExecutions = 0;

            var tasks = ids.Select(id =>
                {
                    ++numExecutions;
                    var query = new EntityQuery<Customer>().Where(c => c.CustomerID == ids[0]);
                    return entityManager.ExecuteQuery(query);

                    // Best practice is to apply ToList() or ToArray() to the task collection immediately
                    // Realizing the collection more than once causes multiple executions of the anon method
                }).ToList();

            var numTasks = tasks.Count();

            // Result of WhenAll is an array of results from the individual anonymous method executions
            // Each individual result is a collection of customers 
            // (only one in this case because of the condition on CustomerId)
            var results = await Task.WhenAll(tasks);
            var numCustomers = results.Sum(customers => customers.Count());

            Assert.AreEqual(actualCustomers, numTasks, "Number of tasks should be " + actualCustomers + ", not " + numTasks);
            Assert.AreEqual(actualCustomers, numExecutions, "Number of excutions should be " + actualCustomers + ", not " + numExecutions);
            Assert.AreEqual(actualCustomers, numCustomers, actualCustomers + " customers should be returned, not " + numCustomers);
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:35,代码来源:ParallelTests.cs

示例4: NewEm

 public static async Task<EntityManager> NewEm(string serviceName) {
   if (MetadataStore.Instance.GetDataService(serviceName) == null) {
     var em = new EntityManager(serviceName);
     await em.FetchMetadata();
     return em;
   } else {
     return new EntityManager(serviceName);
   }
 }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:9,代码来源:TestFns.cs

示例5: NewEm

 public static async Task<EntityManager> NewEm(DataService dataService, MetadataStore metadataStore = null) {
   metadataStore = metadataStore ?? DefaultMetadataStore;
   if (dataService.HasServerMetadata && metadataStore.GetDataService(dataService.ServiceName) == null) {
     var em = new EntityManager(dataService.ServiceName, metadataStore);
     await em.FetchMetadata();
     return em;
   } else {
     return new EntityManager(dataService, metadataStore);
   }
 }
开发者ID:hiddenboox,项目名称:breeze.sharp,代码行数:10,代码来源:TestFns.cs

示例6: HttpClientHandler

    public async Task HttpClientHandler() {
      var  httpClient = new HttpClient(new HttpClientHandler() {
        UseDefaultCredentials = true
      });
      var ds = new DataService(_serviceName, httpClient);
      var em = new EntityManager(ds);
      em.MetadataStore.AllowedMetadataMismatchTypes = MetadataMismatchTypes.MissingCLREntityType;
      var md = await em.FetchMetadata(ds);
      Assert.IsTrue(md != null);

    }
开发者ID:hiddenboox,项目名称:breeze.sharp,代码行数:11,代码来源:MetadataTests.cs

示例7: SetUpAsync

    public async Task<EntityManager> SetUpAsync() {
      var serviceName = "http://localhost:7150/breeze/NorthwindIBModel/";

      if (MetadataStore.Instance.EntityTypes.Count == 0) {
        _em1 = new EntityManager(serviceName);
        await _em1.FetchMetadata();
      } else {
        _em1 = new EntityManager(serviceName);
      }
      return _em1;
      
    }
开发者ID:CodeLancer,项目名称:Breeze,代码行数:12,代码来源:ComplexTypeTests.cs

示例8: SetUpAsync

 public async Task<EntityManager> SetUpAsync() {
   var serviceName = "http://localhost:7150/breeze/NorthwindIBModel/";
   
   if (__metadataStore == null) {
     _em1 = new EntityManager(serviceName);
     await _em1.FetchMetadata();
     __metadataStore = _em1.MetadataStore;
   } else {
     _em1 = new EntityManager(serviceName);
   }
   return _em1;
   
 }
开发者ID:udomsak,项目名称:Breeze,代码行数:13,代码来源:QueryTests.cs

示例9: DoesValidateOnAttachByDefault

        public async Task DoesValidateOnAttachByDefault()
        {
            var manager = new EntityManager(_serviceName); // new empty EntityManager
            await manager.FetchMetadata(); // required before creating a new entity

            var customer = new Customer();
            
            var validationErrors = customer.EntityAspect.ValidationErrors;
            Assert.IsFalse(validationErrors.Any(), "Should be no validation errors before attach.");

            // attach triggers entity validation by default
            manager.AttachEntity(customer);

            Assert.IsTrue(validationErrors.Any(ve => ve.Message.Contains("CompanyName") && ve.Message.Contains("required")), "Should be a validation error stating CompanyName is required.");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:15,代码来源:ValidationTests.cs

示例10: ParallelQueriesBatched

        public async Task ParallelQueriesBatched() {
            var entityManager = new EntityManager(_serviceName);
            await entityManager.FetchMetadata();
            var idQuery = new EntityQuery<Customer>();
            var entities = await entityManager.ExecuteQuery(idQuery);

            var n = 20;
            var ids = entities.Select(c => c.CustomerID).Take(n).ToArray();

            // In case there aren't n customers available
            var actualCustomers = ids.Count();
            int allowedParallelQueries = 5;
            int numActiveQueries = 0;
            int maxActiveQueries = 0;

            var semaphore = new SemaphoreSlim(allowedParallelQueries, allowedParallelQueries);
            var tasks = ids.Select(async id =>
            {
                await semaphore.WaitAsync();
                var query = new EntityQuery<Customer>().Where(c => c.CustomerID == ids[0]);

                // Place the release of the semaphore in a finally block to ensure it always gets released
                try {
                    maxActiveQueries = Math.Max(maxActiveQueries, ++numActiveQueries);
                    return await entityManager.ExecuteQuery(query);
                }
                catch (Exception e) {
                    Assert.Fail("ExecuteQuery() threw " + e.GetType().Name + ": " + e.Message);
                    return new Customer[0];
                }
                finally {
                    --numActiveQueries;
                    semaphore.Release();
                }
                // Best practice is to apply ToList() to the task collection immediately
                // Realizing the collection more than once causes multiple executions of the anon method
            }).ToList();

            // Result of WhenAll is an array of results from the individual anonymous method executions
            // Each individual result is a collection of customers 
            // (only one in this case because of the condition on CustomerId)
            var results = await Task.WhenAll(tasks);
            var numQueriedCustomers = results.Sum(customers => customers.Count());

            Assert.IsTrue(maxActiveQueries <= allowedParallelQueries, "Number of active queries should not exceed " + allowedParallelQueries + ". The max was " + maxActiveQueries);
            Assert.AreEqual(actualCustomers, numQueriedCustomers, actualCustomers + " customers should be returned, not " + numQueriedCustomers);
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:47,代码来源:ParallelTests.cs

示例11: DoesNotValidateOnAttachWhenOptionIsOff

        public async Task DoesNotValidateOnAttachWhenOptionIsOff()
        {
            var manager = new EntityManager(_serviceName); // new empty EntityManager
            await manager.FetchMetadata(); // required before creating a new entity

            // change the default options, turning off "OnAttach"
            var valOpts = new ValidationOptions { ValidationApplicability = ValidationApplicability.OnPropertyChange | ValidationApplicability.OnSave };
            
            // reset manager's options
            manager.ValidationOptions = valOpts;

            var customer = new Customer();
            manager.AttachEntity(customer);

            var validationErrors = customer.EntityAspect.ValidationErrors;
            Assert.IsFalse(validationErrors.Any(), "Should be no validation errors even though CompanyName is required.");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:17,代码来源:ValidationTests.cs

示例12: MetadataMissingClrProperty

    public async Task MetadataMissingClrProperty() {
      
      var ms = new MetadataStore();
      ms.NamingConvention = new MorphedClassNamingConvention();
      var em = new EntityManager(_serviceName, ms);

      em.MetadataStore.AllowedMetadataMismatchTypes = MetadataMismatchTypes.AllAllowable;
        
      var mmargs = new List<MetadataMismatchEventArgs>();
      em.MetadataStore.MetadataMismatch += (s, e) => {
        mmargs.Add(e);
      };
      var x = await em.FetchMetadata();
      Assert.IsTrue(mmargs.Count > 4, "should be more than 4 mismatches, but found: " + mmargs.Count);
      var errors = em.MetadataStore.GetMessages(MessageType.Error);
      Assert.IsTrue(errors.Count() == 0, "should be 0 errors: " + errors.ToAggregateString("..."));
      Assert.IsTrue(em.MetadataStore.GetMessages().Count() >= 4, "should be more than 4 message");
    }
开发者ID:hiddenboox,项目名称:breeze.sharp,代码行数:18,代码来源:PartialMetadataTests.cs

示例13: BadURL

    public async Task BadURL() {

      var serviceName = "http://localhost:7150/breeze/xxxFoo";
      var ds = new DataService(serviceName);
      try {
        var ms = new MetadataStore();
        await ms.FetchMetadata(ds);
      } catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("metadata resource"));
      }

      try {
        var em = new EntityManager(ds);
        await em.FetchMetadata();
      } catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("metadata resource"));
      }
    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:18,代码来源:EntityManagerTests.cs

示例14: NoClrTypes

    public async Task NoClrTypes() {
      
      var serviceName = TestFns.serviceName;
      var ds = new DataService(serviceName);
      try {
        var ms = new MetadataStore();
        await ms.FetchMetadata(ds);
      } catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("Configuration.Instance"), e.Message);
      }

      try {
        var em = new EntityManager(ds);
        await em.FetchMetadata();
      }
      catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("Configuration.Instance"), e.Message);
      }
    }
开发者ID:hiddenboox,项目名称:breeze.sharp,代码行数:19,代码来源:StandaloneTests.cs

示例15: NoClrTypes

    public async Task NoClrTypes() {
      
      var serviceName = "http://localhost:7150/breeze/NorthwindIBModel";
      var ds = new DataService(serviceName);
      try {
        var ms = new MetadataStore();
        await ms.FetchMetadata(ds);
      } catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("Configuration.Instance"), e.Message);
      }

      try {
        var em = new EntityManager(ds);
        await em.FetchMetadata();
      }
      catch (Exception e) {
        Assert.IsTrue(e.Message.Contains("Configuration.Instance"), e.Message);
      }
    }
开发者ID:novice3030,项目名称:breeze.sharp,代码行数:19,代码来源:StandaloneTests.cs


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