本文整理汇总了C#中EntityQuery.Where方法的典型用法代码示例。如果您正苦于以下问题:C# EntityQuery.Where方法的具体用法?C# EntityQuery.Where怎么用?C# EntityQuery.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityQuery
的用法示例。
在下文中一共展示了EntityQuery.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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();
}
示例3: NonGenericQuery
public async Task NonGenericQuery() {
await _emTask;
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C")).Take(3);
var q3 = (EntityQuery)q2;
var results = await _em1.ExecuteQuery(q3);
Assert.IsTrue(results.Cast<Object>().Count() == 3);
}
示例4: QueryWithAFilter
public async Task QueryWithAFilter()
{
var manager = new EntityManager(_serviceName);
// Metadata must be fetched before CreateEntity() can be called
await manager.FetchMetadata();
// Ensure there is at least one active todo item named Wine in the database
var wines = await new EntityQuery<TodoItem>().Where(td => td.Description == "Wine" && !td.IsArchived && !td.IsDone).Execute(manager);
if (!wines.Any()) {
var newWine = manager.CreateEntity<TodoItem>(new {Description = "Wine"});
await manager.SaveChanges();
}
manager.Clear();
//Snippet1
var query1 = new EntityQuery<TodoItem>();
var allTodos = await manager.ExecuteQuery(query1);
Assert.IsTrue(allTodos.Any(), "No TodoItems in the database");
//Snippet2
var query2 = query1.Where(td => !td.IsArchived);
var unarchivedTodos = await manager.ExecuteQuery(query2);
Assert.IsTrue(unarchivedTodos.Any(), "No unarchived TodoItems in the database");
//Snippet3
var query3 = query1.Where(td => !td.IsArchived && !td.IsDone);
var activeTodos = await manager.ExecuteQuery(query3);
Assert.IsTrue(activeTodos.Any(), "No active TodoItems in the database");
//Snippet4
var query4 = query1.Where(td => td.Description.Contains("Wine"));
var wineTodos = await manager.ExecuteQuery(query4);
Assert.IsTrue(allTodos.Any(), "No Wine TodoItems in the database");
//Snippet5
// Execute above query locally
var localWineTodos = manager.ExecuteQueryLocally(query4);
Assert.AreEqual(wineTodos.Count(), localWineTodos.Count(), "Got " + localWineTodos.Count() + " local wine TodoItems");
}
示例5: WhereAnyOrderBy
public async Task WhereAnyOrderBy() {
var em1 = await TestFns.NewEm(_serviceName);
var q = new EntityQuery<Foo.Customer>("Customers").Expand("Orders");
var q2 = q.Where(c => c.CompanyName.StartsWith("C") && c.Orders.Any(o => o.Freight > 10));
var q3 = q2.OrderBy(c => c.City);
var r = await q3.Execute(em1);
Assert.IsTrue(r.Count() > 0);
Assert.IsTrue(r.All(r1 => r1.GetType() == typeof(Foo.Customer)), "should all get customers");
var rLocal = q3.ExecuteLocally(em1);
Assert.IsTrue(rLocal.Count() == r.Count());
Assert.IsTrue(r.SequenceEqual(rLocal), "should be in the same order");
}
示例6: InlineCount2
public async Task InlineCount2() {
await _emTask;
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C")).Take(2);
var q3 = q2.InlineCount();
var results = await q3.Execute(_em1);
var count = ((IHasInlineCount)results).InlineCount;
Assert.IsTrue(results.Count() == 2);
Assert.IsTrue(results.Count() < count, "counts should be the same");
Assert.IsTrue(results.All(r1 => r1.GetType() == typeof(Foo.Customer)), "should all get customers");
}
示例7: ExpandNonScalar
public async Task ExpandNonScalar() {
await _emTask;
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C"));
var q3 = q2.Expand(c => c.Orders);
var results = await q3.Execute(_em1);
Assert.IsTrue(results.Count() > 0);
var ok = results.All(r1 =>
r1.GetType() == typeof(Foo.Customer) &&
r1.Orders.Count() > 0 &&
r1.Orders.All(o => o.GetType() == typeof(Foo.Order)) &&
r1.Orders.All(o => o.Customer == r1));
Assert.IsTrue(ok, "every Customer should contain a collection of Orders");
ok = results.All(r1 => r1.CompanyName.Length > 0);
Assert.IsTrue(ok, "and should have a populated company name");
}
示例8: SelectAnonWithScalarSelf
public async Task SelectAnonWithScalarSelf() {
Assert.Inconclusive("OData doesn't support this kind of query (I think)");
return;
// Pretty sure this is an issue with OData not supporting this syntax.
await _emTask;
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C"));
var q3 = q2.Select(c => new { c.CompanyName, Customer = c });
var results = await q3.Execute(_em1);
Assert.IsTrue(results.Count() > 0);
var ok = results.All(r1 => r1.CompanyName.Length > 0);
Assert.IsTrue(ok, "anon type should have a populated company name");
ok = results.All(r1 => r1.Customer.GetType() == typeof(Foo.Customer));
Assert.IsTrue(ok, "anon type should have a populated 'Customer'");
}
示例9: SelectAnonWithScalarEntity
public async Task SelectAnonWithScalarEntity() {
var em1 = await TestFns.NewEm(_serviceName);
var q = new EntityQuery<Foo.Order>("Orders");
var q2 = q.Where(c => c.Freight > 500);
var q3 = q2.Select(c => new { c.Customer, c.Freight });
var results = await q3.Execute(em1);
// get rid of orders with null customers
results = results.Where(r => r.Customer != null);
Assert.IsTrue(results.Any());
var ok = results.All(r1 => r1.Freight > 500);
Assert.IsTrue(ok, "anon type should the right freight");
ok = results.All(r1 => r1.Customer.GetType() == typeof(Foo.Customer));
Assert.IsTrue(ok, "anon type should have a populated 'Customer'");
}
示例10: SelectIntoCustom
public async Task SelectIntoCustom() {
var em1 = await TestFns.NewEm(_serviceName);
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C"));
await em1.ExecuteQuery(q2.Expand("Orders")); // precache for later local query;
var q3 = q2.Select(c => new Dummy() { CompanyName = c.CompanyName, Orders = c.Orders });
var r3 = await q3.Execute(em1);
Assert.IsTrue(r3.Count() > 0);
var ok = r3.All(r1 =>
r1.GetType() == typeof(Dummy) &&
r1.Orders.Count() > 0 &&
r1.Orders.All(o => o.GetType() == typeof(Foo.Order)));
Assert.IsTrue(ok, "every Dummy should contain a collection of Orders");
ok = r3.All(r1 => r1.CompanyName.Length > 0);
Assert.IsTrue(ok, "and should have a populated company name");
var r3Local = em1.ExecuteQueryLocally(q3);
Assert.IsTrue(r3.Count() == r3Local.Count());
ok = r3Local.All(r1 =>
r1.GetType() == typeof(Dummy) &&
r1.Orders.Count() > 0 &&
r1.Orders.All(o => o.GetType() == typeof(Foo.Order)));
Assert.IsTrue(ok, "every Dummy should contain a collection of Orders");
}
示例11: WithEntityManager
public async Task WithEntityManager() {
var em1 = await TestFns.NewEm(_serviceName);
var q = new EntityQuery<Foo.Customer>("Customers");
var q2 = q.Where(c => c.CompanyName.StartsWith("C"));
var q3 = q2.OrderBy(c => c.CompanyName).Take(2);
var r = await q3.With(em1).Execute();
Assert.IsTrue(r.Count() == 2);
var r3 = q3.With(em1).ExecuteLocally();
Assert.IsTrue(r3.Count() == 2);
}
示例12: WhereAnyOrderBy
public async Task WhereAnyOrderBy() {
await _emTask;
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 results = await q3.Execute(_em1);
Assert.IsTrue(results.Count() > 0);
Assert.IsTrue(results.All(r1 => r1.GetType() == typeof(Foo.Customer)), "should all get customers");
var cust = results.First();
var companyName = cust.CompanyName;
var custId = cust.CustomerID;
var orders = cust.Orders;
}
示例13: CompositeNotPred
public async Task CompositeNotPred() {
var entityManager = await TestFns.NewEm(_serviceName);
// Start with a base query for all Orders
var baseQuery = new EntityQuery<Order>();
var p1 = PredicateBuilder.Create<Order>(o => o.Freight > 100);
var pred = p1.Not();
var query = baseQuery.Where(pred);
var orders = await entityManager.ExecuteQuery(query);
Assert.IsTrue(orders.Any(), "There should be orders");
pred = pred.Not();
var query2 = baseQuery.Where(pred);
}
示例14: OrderQuery
private EntityQuery<OrderFlow> OrderQuery(EntityQuery<OrderFlow> query)
{
query = query.Where(e => e.OrderState == (int)OrderState_Enum.Approvaling);
if (WebContext.Current.User.IsInRole(RegistrationDataResources.Roles_Approval))
{
query = query.Where(e => e.ApprovalUser == WebContext.Current.User.Name);
}
return query;
}
示例15: WhereAnyOrderBy2
public async Task WhereAnyOrderBy2() {
await _emTask;
var q = new EntityQuery<Foo.Customer>("Customers");
// just to fill up some extra custs
var rBase = await q.Take(10).Execute(_em1);
var q2 = q.Where(c => c.CompanyName.StartsWith("C") && c.Orders.Any(o => o.Freight > 10));
var q3 = q2.OrderBy(c => c.City).Expand("Orders");
var r = await q3.Execute(_em1);
Assert.IsTrue(r.Count() > 0);
Assert.IsTrue(r.All(r1 => r1.GetType() == typeof(Foo.Customer)), "should all get customers");
var rLocal = q3.ExecuteLocally(_em1);
Assert.IsTrue(rLocal.Count() == r.Count());
Assert.IsTrue(r.SequenceEqual(rLocal), "should be in the same order");
}