DevForce Help Reference
ExecuteQuery(IEntityQuery) Method
Example 


Executes the specified query.
Syntax
'Declaration
 
Public Overloads Function ExecuteQuery( _
   ByVal query As IEntityQuery _
) As IEnumerable
'Usage
 
Dim instance As EntityManager
Dim query As IEntityQuery
Dim value As IEnumerable
 
value = instance.ExecuteQuery(query)
public IEnumerable ExecuteQuery( 
   IEntityQuery query
)

Parameters

query

Return Value

A collection of IEntityQuery.ElementType
Remarks
In Silverlight and Windows Store applications use ExecuteQueryAsync(IEntityQuery) instead unless a cache-only query is performed.
Example
public void ExecuteQuerySamples() {
  DomainModelEntityManager mgr = new DomainModelEntityManager();

  // 1a) Query by type 
  EntityQuery<Customer> query1a = mgr.Customers;
  IEnumerable<Customer> results1a = mgr.ExecuteQuery<Customer>(query1a);
  // 1b) Query by type with a query strategy
  EntityQuery<Customer> query1b = mgr.Customers.With(QueryStrategy.CacheOnly);
  IEnumerable<Customer> results1b = mgr.ExecuteQuery<Customer>(query1b);
  // 1c) Query by type using immediate execution
  List<Customer> results1c = mgr.Customers.ToList();

  // 2a) Query by EntityKey
  EntityKey key = new EntityKey(typeof(Customer), "ALFKI");
  var customer2a = key.ToQuery().FirstOrNullEntity();
  // 2b) Query by EntityKey with a query strategy
  var customer2b = key.ToQuery().With(QueryStrategy.CacheOnly).FirstOrNullEntity();

  // 3a) Query by a list of EntityKeys
  EntityKeyList keys = new EntityKeyList(typeof(Customer));
  keys.Add(new EntityKey(typeof(Customer), "ALFKI"));
  keys.Add(new EntityKey(typeof(Customer), "BONAP"));
  EntityKeyQuery query3a = keys.ToQuery();
  var results3a = mgr.ExecuteQuery(query3a);
  // 3b) Query by a list of EntityKeys with query strategy
  var results3b = mgr.ExecuteQuery(query3a.With(QueryStrategy.CacheOnly));

  // 4a) Query with an EntityQuery
  IEntityQuery<Customer> q4 = mgr.Customers.Where(c => c.CustomerID.StartsWith("A"));
  IEnumerable<Customer> results4a = mgr.ExecuteQuery<Customer>(q4);
  // 4b) Query with an EntityQuery and query strategy
  IEnumerable<Customer> results4b = mgr.ExecuteQuery<Customer>(q4.With(QueryStrategy.CacheOnly));
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityManager Class
EntityManager Members
Overload List

Send Feedback