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


C# EntityManager.GetEntities方法代码示例

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


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

示例1: ExportImportFromIsolatedStorage

        public async Task ExportImportFromIsolatedStorage()
        {
            var manager1 = new EntityManager(_serviceName);
            await PrimeCache(manager1);
            var expectedEntityCount = manager1.GetEntities().Count();

            var exportData = manager1.ExportEntities();

            var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            string importData;
            using (var isoStream = new IsolatedStorageFileStream("ExportEntities.txt", FileMode.Create, isoStore))
            {
                using (var writer = new StreamWriter(isoStream))
                {
                    writer.Write(exportData);
                }
            }

            using (var isoStream = new IsolatedStorageFileStream("ExportEntities.txt", FileMode.Open, isoStore))
            {
                using (var reader = new StreamReader(isoStream))
                {
                    importData = reader.ReadToEnd();
                }
            }
            
            // import into a new EntityManager
            var manager2 = new EntityManager(_serviceName);
            manager2.ImportEntities(importData);

            Assert.AreEqual(expectedEntityCount, manager2.GetEntities().Count());
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:32,代码来源:ExportImportTests.cs

示例2: ExportEntitiesToFileWithoutMetadata

        public async Task ExportEntitiesToFileWithoutMetadata()
        {
            var manager = new EntityManager(_serviceName);
            await PrimeCache(manager);
            var entitiesToExport = manager.GetEntities<Customer>();

            var exportData = manager.ExportEntities(entitiesToExport, false);

            var mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            File.WriteAllText(mydocpath + @"\ExportEntitiesWithoutMetadata.txt", exportData);

            Assert.IsTrue(File.Exists(mydocpath + @"\ExportEntitiesWithoutMetadata.txt"), "ExportEntitiesWithoutMetadata.txt should have been created");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:13,代码来源:ExportImportTests.cs

示例3: DeleteWithoutQuery

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

      var emp = new Employee();
      emp.FirstName = "Test Fn";
      emp.LastName = "Test Fn";
      em1.AddEntity(emp);
      var sr = await em1.SaveChanges();

      Assert.IsTrue(sr.Entities.Count == 1, "should have saved 1 entity");
      Assert.IsTrue(sr.Entities.First() == emp, "should be the same emp");
      var em2 = new EntityManager(em1);
      em2.ImportEntities(em1.ExportEntities());
      var sameEmp = (Employee) em2.GetEntities().First();
      Assert.IsTrue(emp.EntityAspect.EntityKey == sameEmp.EntityAspect.EntityKey, "should have the same key");
      sameEmp.EntityAspect.Delete();
      Assert.IsTrue(sameEmp.EntityAspect.EntityState.IsDeleted());
      var sr2 = await em2.SaveChanges();
      Assert.IsTrue(sr2.Entities.First() == sameEmp, "should still be the same emp");
      Assert.IsTrue(sameEmp.EntityAspect.EntityState.IsDetached());
      Assert.IsTrue(em2.GetEntities().Count() == 0, "should be no entities");

    }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:23,代码来源:SaveTests.cs

示例4: ExpImpTempKeyFixup2

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

      var q = new EntityQuery<Foo.Supplier>("Suppliers").Where(s => s.CompanyName.StartsWith("P"));

      var suppliers = await q.Execute(em1);

      Assert.IsTrue(suppliers.Count() > 0, "should be some suppliers");
      var orderIdProp = MetadataStore.Instance.GetEntityType("Order").KeyProperties[0];
      em1.KeyGenerator.GetNextTempId(orderIdProp);

      var order1 = new Order();
      var emp1 = new Employee();
      em1.AddEntity(order1); em1.AddEntity(emp1);
      emp1.LastName = "bar";
      var cust1 = new Customer() { CompanyName = "Foo" };
      order1.Employee = emp1;
      order1.Customer = cust1;
      var exportedEm = em1.ExportEntities(null, false);

      var em2 = new EntityManager(em1);
      em2.ImportEntities(exportedEm);

      var suppliers2 = em2.GetEntities<Supplier>().ToList();
      Assert.IsTrue(suppliers.Count() == suppliers2.Count, "should be the same number of suppliers");
      var addedOrders = em2.GetEntities<Order>(EntityState.Added);
      Assert.IsTrue(addedOrders.Count() == 1, "should be 1 added order");
      var order1x = addedOrders.First();
      var cust1x = order1x.Customer;
      Assert.IsTrue(cust1x.CompanyName == "Foo", "customer company name should be 'Foo'");
      var emp1x = order1x.Employee;
      Assert.IsTrue(emp1x.LastName == "bar", "lastName should be 'bar'");

    }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:34,代码来源:ExportImportTests.cs

示例5: ExpImpSelectedEntitiesWithChanges

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

      var q = new EntityQuery<Foo.Customer>("Customers").Take(5);

      var results = await q.Execute(em1);

      Assert.IsTrue(results.Count() > 0);
      var custs = results.Take(2).ToList();
      custs.ForEach(c => c.City = "Paris");
      var emp1 = em1.CreateEntity<Employee>();
      var emp2 = em1.CreateEntity<Employee>();

      var exportedEntities = em1.ExportEntities(new IEntity[] { custs[0], custs[1], emp1, emp2 }, false);

      var em2 = new EntityManager(em1);
      var impResult = em2.ImportEntities(exportedEntities);
      var allEntities = em2.GetEntities();

      Assert.IsTrue(impResult.ImportedEntities.Count == 4, "should have imported 4 entities");
      Assert.IsTrue(impResult.TempKeyMap.Count == 2);
      Assert.IsTrue(impResult.TempKeyMap.All(kvp => kvp.Key == kvp.Value), "imported entities should have same key values");
      Assert.IsTrue(allEntities.Count() == 4, "should have 4 entities in cache");
      Assert.IsTrue(em2.GetEntities<Customer>().All(c => c.EntityAspect.EntityState.IsModified()));
      Assert.IsTrue(em2.GetEntities<Employee>().All(c => c.EntityAspect.EntityState.IsAdded()));

    }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:27,代码来源:ExportImportTests.cs

示例6: ExportImportUnchangedEntities

        public async Task ExportImportUnchangedEntities()
        {
            var manager = new EntityManager(_serviceName);
            await PrimeCache(manager);

            // modify one of the entities
            var customer = manager.GetEntities<Customer>().First();
            customer.City = "Paris";
            var expectedUnchangedEntityCount = manager.GetEntities().Count() - 1;

            // export only Unchanged entities
            var exportData = manager.ExportEntities(manager.GetEntities(EntityState.Unchanged));

            // import into a new EntityManager
            var manager2 = new EntityManager(_serviceName);
            manager2.ImportEntities(exportData);

            Assert.AreEqual(expectedUnchangedEntityCount, manager2.GetEntities().Count());
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:19,代码来源:ExportImportTests.cs

示例7: ExportImportSelectedEntities

        public async Task ExportImportSelectedEntities()
        {
            var manager = new EntityManager(_serviceName);
            var manager2 = new EntityManager(_serviceName);
            await PrimeCache(manager);
            var customers = manager.GetEntities<Customer>().ToList();

            var exportData1 = manager.ExportEntities(new IEntity[] {customers[0]}); // array with 1 customer
            var importData1 = manager2.ImportEntities(exportData1);
            Assert.AreEqual(1, importData1.ImportedEntities.Count);
            manager2.Clear();

            var exportData2 = manager.ExportEntities(new IEntity[] {customers[0], customers[1]}); // array of 2 customers
            var importData2 = manager2.ImportEntities(exportData2);
            Assert.AreEqual(2, importData2.ImportedEntities.Count);
            manager2.Clear();

            Assert.AreEqual(0, manager.GetChanges().Count());
            customers.First().City = "Paris";
            var exportData3 = manager.ExportEntities(manager.GetChanges()); // all pending changes
            var importData3 = manager2.ImportEntities(exportData3);
            Assert.AreEqual(1, importData3.ImportedEntities.Count);
            manager2.Clear();

            var selectedCustomerQuery = new EntityQuery<Customer>().Where(customer => customer.City.StartsWith("P"));
            var selectedCustomers = manager.ExecuteQueryLocally(selectedCustomerQuery); // cache-only query returns synchronously
            var exportData4 = manager.ExportEntities(selectedCustomers); // the 'P' customers 
            var importData4 = manager2.ImportEntities(exportData4);
            Assert.AreEqual(1, importData4.ImportedEntities.Count);
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:30,代码来源:ExportImportTests.cs

示例8: ExportImportEntitiesWithoutMetadata

        public async Task ExportImportEntitiesWithoutMetadata()
        {
            var manager1 = new EntityManager(_serviceName);
            await PrimeCache(manager1);
            var selectedEntities = manager1.GetEntities<Customer>().ToList();

            // export the selected entities without metadata
            var exportData = manager1.ExportEntities(selectedEntities, false);

            //TODO: What is the equivalent in breeze.sharp?
            // a virginal manager would throw exception on import
            // because it lacks the metadata
            // var em2 = new EntityManager(); 
            
            // creates a new EntityManager with the same configuration as another EntityManager but without any entities
            var manager2 = new EntityManager(manager1);
            var importResult = manager2.ImportEntities(exportData);

            Assert.AreEqual(selectedEntities.Count(), importResult.ImportedEntities.Count);
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:20,代码来源:ExportImportTests.cs

示例9: ExportImportEntitiesOverwriteChanges

        public async Task ExportImportEntitiesOverwriteChanges()
        {
            var manager1 = new EntityManager(_serviceName);
            await PrimeCache(manager1);

            // modify all the customers in manager1
            var parisCustomers = manager1.GetEntities<Customer>().ToList();
            parisCustomers.ForEach(c => c.City = "Paris");

            var exportData = manager1.ExportEntities();

            var manager2 = new EntityManager(_serviceName);
            await PrimeCache(manager2);

            // modify all the "same" customers in manager2 
            var londonCustomers = manager2.GetEntities<Customer>().ToList();
            londonCustomers.ForEach(c => c.City = "London");

            // overwrite changes in manager2 with the exported data
            manager2.ImportEntities(exportData, new ImportOptions(MergeStrategy.OverwriteChanges));
            // all the customers should now be in "Paris"
            Assert.IsTrue(manager2.GetEntities<Customer>().All(c => c.City == "Paris"), "All cities should = Paris");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:23,代码来源:ExportImportTests.cs

示例10: ExportImportEntitiesPreserveChanges

        public async Task ExportImportEntitiesPreserveChanges()
        {
            var manager1 = new EntityManager(_serviceName);
            await PrimeCache(manager1);

            // modify all the customers in manager1
            var parisCustomers = manager1.GetEntities<Customer>().ToList();
            parisCustomers.ForEach(c => c.City = "Paris");

            var exportData = manager1.ExportEntities();

            var manager2 = new EntityManager(_serviceName);
            await PrimeCache(manager2);

            // modify all the "same" customers in manager2 
            var londonCustomers = manager2.GetEntities<Customer>().ToList();
            londonCustomers.ForEach(c => c.City = "London");

            // changes in manager2 are preserved by default
            var importResult = manager2.ImportEntities(exportData);

            // so nothing should have been imported
            Assert.AreEqual(0, importResult.ImportedEntities.Count);
            Assert.AreEqual(londonCustomers.Count, manager2.GetEntities().Count());
            // all the customers should still be in "London"
            Assert.IsTrue(manager2.GetEntities<Customer>().All(c => c.City == "London"), "All cities should = London");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:27,代码来源:ExportImportTests.cs

示例11: ExportImportEntities

        public async Task ExportImportEntities()
        {
            var manager1 = new EntityManager(_serviceName);
            await PrimeCache(manager1);
            var expectedEntityCount = manager1.GetEntities().Count();

            var exportData = manager1.ExportEntities();

            // import into a new EntityManager
            var manager2 = new EntityManager(_serviceName);
            manager2.ImportEntities(exportData);

            Assert.AreEqual(expectedEntityCount, manager2.GetEntities().Count());
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:14,代码来源:ExportImportTests.cs

示例12: ExpImpEntitiesWithEnum

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

      var q = new EntityQuery<Foo.Role>("Roles").Take(5);

      var results = await q.Execute(em1);

      Assert.IsTrue(results.Any());
      var exportedEntities = em1.ExportEntities();

      File.WriteAllText("c:/temp/emExportWithEnum.txt", exportedEntities);

      var em2 = new EntityManager(em1);

      em2.ImportEntities(exportedEntities);
      var roleTypes = em2.GetEntities<Role>().Select(x => x.RoleType).ToList();

	  Assert.IsTrue(roleTypes.Count == 5, "should have imported 5 entities");
	}
开发者ID:hiddenboox,项目名称:breeze.sharp,代码行数:20,代码来源:ExportImportTests.cs

示例13: AssertGotOrderDetails

    private void AssertGotOrderDetails(EntityManager entityManager, IEnumerable<Order> orders) {
      var odType = entityManager.MetadataStore.GetEntityType("OrderDetail");

      // Check that there are order details in cache
      var odsInCache = entityManager.GetEntities<OrderDetail>();
      Assert.IsTrue(odsInCache.Any(), "Should have OrderDetails in cache; got " + odsInCache.Count());

      // Check the first order was fixed up properly
      var firstOrder = orders.FirstOrDefault();
      Assert.IsNotNull(firstOrder, "There should be at least one order returned");
      Assert.IsTrue(firstOrder.OrderDetails.Any(), "First order should have order details");

      // To manually confirm these results, run this SQL:
      // select count(*) from OrderDetail where OrderID in 
      //   (select OrderID from [Order] where CustomerID = '785efa04-cbf2-4dd7-a7de-083ee17b6ad2')
    }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:16,代码来源:QueryTests.cs


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