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


C# EntityQuery类代码示例

本文整理汇总了C#中EntityQuery的典型用法代码示例。如果您正苦于以下问题:C# EntityQuery类的具体用法?C# EntityQuery怎么用?C# EntityQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: LinqCommand

        public EntityInfo TargetEntity; //for delete, insert, update

        #endregion Fields

        #region Constructors

        public LinqCommand(EntityQuery query, LinqCommandType commandType, LinqCommandKind kind, EntityInfo targetEntity)
        {
            Kind = kind;
              CommandType = commandType;
              Query = query;
              TargetEntity = targetEntity;
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:13,代码来源:LinqCommand.cs

示例2: NullForeignKey

    public async Task NullForeignKey() {
      await _emTask;
      var prod1 = new Product();
      
      _em1.AttachEntity(prod1);
      prod1.ProductName = "Test";
      prod1.SupplierID = null;

      var q0 = new EntityQuery<Product>().Where(p => p.Supplier != null).Take(2).Expand(p => p.Supplier);
      var r0 = (await q0.Execute(_em1)).ToList();
      Assert.IsTrue(r0.Count() == 2);
      Assert.IsTrue(r0.All(p => p.Supplier != null));
      var p0 = r0[0];
      var p1 = r0[1];
      var s0 = p0.Supplier;
      var s1 = p1.Supplier;

      Assert.IsTrue(s0.Products.Contains(p0));
      p0.Supplier = null;
      Assert.IsTrue(p0.SupplierID == null);
      Assert.IsTrue(!s0.Products.Contains(p0));
      
      Assert.IsTrue(s1.Products.Contains(p1));
      p1.SupplierID = null;
      Assert.IsTrue(p1.Supplier == null);
      Assert.IsTrue(!s1.Products.Contains(p1));
    }
开发者ID:CodeLancer,项目名称:Breeze,代码行数:27,代码来源:AttachTests.cs

示例3: 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

示例4: CompositePred

    public async Task CompositePred() {
      var entityManager = await TestFns.NewEm(_serviceName);

      // Start with a base query for all Orders
      var baseQuery = new EntityQuery<Order>();

      // A Predicate is a condition that is true or false
      // Combine two predicates with '.And' to
      // query for orders with freight cost over $100
      // that were ordered after April 1, 1998
      var p1 = PredicateBuilder.Create<Order>(o => o.Freight > 100);
      var p2 = PredicateBuilder.Create<Order>(o => o.OrderDate > new DateTime(1998, 3, 1));
      var pred = p1.And(p2);
      var query = baseQuery.Where(pred);
      var orders = await entityManager.ExecuteQuery(query);
      Assert.IsTrue(orders.Any(), "There should be orders");
      Assert.IsTrue(orders.All(o => o.Freight > 100 && o.OrderDate > new DateTime(1998,3,1)), 
        "There should be the right orders");

      // Yet another way to ask the same question
      pred = PredicateBuilder.Create<Order>(o => o.Freight > 100)
          .And(PredicateBuilder.Create<Order>(o => o.OrderDate > new DateTime(1998, 3, 1)));
      var query2 = baseQuery.Where(pred);
      var orders2 = await entityManager.ExecuteQuery(query2);
      Assert.IsTrue(orders2.Count() == orders.Count());

      // Yet another way to ask the same question
      pred = PredicateBuilder.Create<Order>(o => o.Freight > 100)
          .Or(PredicateBuilder.Create<Order>(o => o.OrderDate > new DateTime(1998, 3, 1)));
      var query3 = baseQuery.Where(pred);

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

示例5: 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

示例6: SaveCustomersAndNewOrder

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

      var q = new EntityQuery<Customer>("Customers").Where(c => c.CompanyName.StartsWith("A"));
      var custs = await q.Execute(em1);
      Assert.IsTrue(custs.Count() > 0, "should be some results");
      custs.ForEach(c => c.Fax = TestFns.MorphString(c.Fax));
      var cust1 = em1.CreateEntity<Customer>();
      cust1.CompanyName = "Test001";
      var cust1Key = cust1.EntityAspect.EntityKey;
      var order1 = em1.CreateEntity<Order>();
      var order1Key = order1.EntityAspect.EntityKey;

      order1.Customer = cust1;
      var custCount = em1.GetEntities<Customer>().Count();
      Assert.IsTrue(em1.HasChanges(), "hasChanges should be true");
      Assert.IsTrue(em1.GetChanges().Count() > 0, "should have changes");
      var saveResult = await em1.SaveChanges();
      Assert.IsTrue(saveResult.Entities.Count == custs.Count() + 2, "should have returned the correct number of entities");
      Assert.IsTrue(order1Key != order1.EntityAspect.EntityKey, "order1 entityKey should have changed");
      Assert.IsTrue(cust1Key != cust1.EntityAspect.EntityKey, "cust1 entityKey should have changed");
      Assert.IsTrue(order1.Customer == cust1, "cust attachment should be the same");
      Assert.IsTrue(cust1.Orders.Contains(order1), "order attachment should be the same");
      Assert.IsTrue(saveResult.KeyMappings[order1Key] == order1.EntityAspect.EntityKey, "keyMapping for order should be avail");
      Assert.IsTrue(saveResult.KeyMappings[cust1Key] == cust1.EntityAspect.EntityKey, "keyMapping for order should be avail");
      Assert.IsTrue(em1.GetEntities<Customer>().Count() == custCount, "should be the same number of custs");
      Assert.IsTrue(order1.EntityAspect.EntityState.IsUnchanged());
      Assert.IsTrue(cust1.EntityAspect.EntityState.IsUnchanged());
      Assert.IsTrue(em1.HasChanges() == false, "hasChanges should be false");
      Assert.IsTrue(em1.GetChanges().Count() == 0, "should be no changes left");
    }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:31,代码来源:SaveTests.cs

示例7: ExecuteQuery

    private async void ExecuteQuery() {
      var serviceName = "http://localhost:7150/breeze/NorthwindIBModel/";
      var em = new EntityManager(serviceName);

      
      

      var query = "Employees";
      
      // var metadata = await client.FetchMetadata();

      var q = new EntityQuery<Foo.Customer>("Customers");
      var q2 = q.Where(c => c.CompanyName.StartsWith("C") && c.Orders.Any(o => o.Freight > 10));
      var q3 = q2.OrderBy(c => c.CompanyName).Skip(2);
      // var q3 = q2.Select(c => c.Orders); // fails
      // var q4 = q2.Select(c => new Dummy() { Orders = c.Orders}  );
      // var q4 = q2.Select(c => new { Orders = c.Orders });
      // var q4 = q3.Select(c => new { c.CompanyName, c.Orders });
      var x = await q3.Execute(em);
      //var q3 = q2.Expand(c => c.Orders);
      //var q4 = q3.OrderBy(c => c.CompanyName);
      //var zzz = q4.GetResourcePath();
      //var x = await q4.Execute(em);
      var addresses = x.Select(c => {
        var z = c.CompanyName;
        var cid = c.CustomerID;
        c.CompanyName = "Test123";
        return c.Address;
      }).ToList();
      
    }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:31,代码来源:MainWindow.xaml.cs

示例8: SimpleConcurrencyFault

        public async Task SimpleConcurrencyFault() {

            Configuration.Instance.ProbeAssemblies(typeof(Customer).Assembly);

            // Query Alfred
            var entityManager1 = new EntityManager(_northwindServiceName);
            var query = new EntityQuery<Customer>().Where(c => c.CustomerID == _alfredsID);
            var alfred1 = (await entityManager1.ExecuteQuery(query)).FirstOrDefault();

            // Query a second copy of Alfred in a second entity manager
            var entityManager2 = new EntityManager(_northwindServiceName);
            var alfred2 = (await entityManager2.ExecuteQuery(query)).FirstOrDefault();

            // Modify and save the first Alfred
            alfred1.ContactTitle += "X";

            // Currently, this throws due to "changes to an original record may not be saved"
            // ...whatever that means
            var saveResult1 = await entityManager1.SaveChanges();

            // Attempt to modify and save the second Alfred
            alfred2.ContactName += "Y";
            try {
                var saveResult2 = await entityManager2.SaveChanges();
            }
            catch (SaveException e) {
                var message = e.Message;
            }
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:29,代码来源:ConcurrencyTests.cs

示例9: EntityQueryPagedCollectionView

 // called by ObjectDataSource - set sort, grouping and filter info before calling load
 internal EntityQueryPagedCollectionView(EntityQuery query, int pageSize, int loadSize, 
   SortDescriptionCollection sortDescriptors, ObservableCollection<GroupDescription> groupDescriptors, IPredicateDescription filter) 
  : this(query, pageSize, loadSize, true, false) {
   sortDescriptors.ForEach(d => SortDescriptions.Add(d));
   groupDescriptors.ForEach(d=> GroupDescriptions.Add(d));
   SetQueryFilter(filter);
   Refresh();
 }
开发者ID:IdeaBlade,项目名称:DevForce.Utilities,代码行数:9,代码来源:EntityQueryPagedCollectionView.cs

示例10: RefreshAsync

        public async Task RefreshAsync()
        {
            var query = new EntityQuery<Person>();
            IEnumerable<Person> persons = await _entityManager.ExecuteQuery<Person>(query);
            Person = persons.FirstOrDefault();

            // TODO: Also get distastes, make it part of the same query.
        }
开发者ID:dayewah,项目名称:crisischeckin,代码行数:8,代码来源:ClientModel.cs

示例11: SimpleQuery

    public async Task SimpleQuery() {
      await _emTask;
      var q = new EntityQuery<Customer>();

      var results = await _em1.ExecuteQuery(q);

      Assert.IsTrue(results.Cast<Object>().Count() > 0);

    }
开发者ID:niaher,项目名称:Breeze,代码行数:9,代码来源:QueryTests.cs

示例12: WithOnlyExpand

 public async Task WithOnlyExpand() {
   await _emTask;
   var q = new EntityQuery<Customer>().Take(3);
   var r0 = await _em1.ExecuteQuery(q);
   var q1 = new EntityQuery<Customer>().Expand("Orders");
   var r1 = q1.ExecuteLocally(_em1);
   Assert.IsTrue(r0.Count() == r1.Count());
   
 }
开发者ID:nbogale,项目名称:Breeze,代码行数:9,代码来源:LocalQueryTests.cs

示例13: WithOnlyExpand

 public async Task WithOnlyExpand() {
   var em1 = await TestFns.NewEm(_serviceName);
   var q = new EntityQuery<Customer>().Take(3);
   var r0 = await em1.ExecuteQuery(q);
   var q1 = new EntityQuery<Customer>().Expand("Orders");
   var r1 = q1.ExecuteLocally(em1);
   Assert.IsTrue(r0.Count() == r1.Count());
   
 }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:9,代码来源:LocalQueryTests.cs

示例14: QueryAbstractWithOr

    public async Task QueryAbstractWithOr() {
      var em1 = await TestFns.NewEm(_serviceName);
      var q = new EntityQuery<Fruit>().From("Fruits").Where(f => f.Name == "Apple" || f.Name == "Foo" || f.Name == "Papa");

      var r0 = await em1.ExecuteQuery(q);
      Assert.IsTrue(r0.Count() > 0);
      var fruit1 = r0.First();
      Assert.IsTrue(fruit1 is Apple, "fruit should be an Apple");

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

示例15: WebApiDomainClientAsyncResult

        /// <summary>
        /// Initializes a new <see cref="WebDomainClientAsyncResult&lt;TContract&gt;"/> instance used for Query operations.
        /// </summary>
        /// <param name="callback">Optional <see cref="AsyncCallback"/> to invoke upon completion.</param>
        /// <param name="asyncState">Optional user state information that will be passed to the <paramref name="callback"/>.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="domainClient"/> is null.</exception>
        /// <exception cref="ArgumentNullException">if <paramref name="endOperationMethod"/> is null.</exception>
        private WebApiDomainClientAsyncResult(WebApiDomainClient domainClient, EntityQuery query, AsyncCallback callback, object asyncState)
            : base(domainClient, callback, asyncState)
        {
            // base class validates domainClient
            if (query == null)
                throw new ArgumentNullException("query");

            _interfaceType = domainClient.ServiceInterfaceType;
            _operationName = query.QueryName;
        }
开发者ID:Daniel-Svensson,项目名称:OpenRiaPlayground,代码行数:17,代码来源:WebApiDomainClientAsyncResult.cs


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