Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found that I did not need to use reflection to invoke the Load method (negating the need for the delegate), instead I call Load directly by creating a generic method based on Entity type. Here is what I came up with for anyone interested:</p> <pre><code> /// &lt;summary&gt; /// The Action callback for the LoadEntityQuery handler. This callback is used to respond to the /// LoadEntityQuery when all Load calls are complete. See the Handle method /// &lt;/summary&gt; private Action&lt;LoadEntityQueryResult&gt; _reply = null; /// &lt;summary&gt; /// Accumulator used to determine when the last entity has been loaded /// &lt;/summary&gt; private int EntityCount { get; set; } /// &lt;summary&gt; /// Collective error container for Errors from the LoadOperation. This is value is returned via /// the _reply callback to the calling code. /// &lt;/summary&gt; private List&lt;Exception&gt; Errors = null; public void Handle(LoadEntityQuery loadQuery, Action&lt;LoadEntityQueryResult&gt; reply) { _reply = reply; Errors = new List&lt;Exception&gt;(); EntityCount = loadQuery.Entities.Count(); MethodInfo _loadOpMethod = this.GetType().GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Instance); int _entityCount = loadQuery.Entities.Count(); foreach (var entry in loadQuery.Entities) { Type entityType = entry.Key; Type _contextType = EmployeeJobsContext.Instance.GetType(); MethodInfo _methodInfo = (from x in _contextType.GetMethods() where x.ReturnType.BaseType == typeof(EntityQuery) from y in x.ReturnType.GetGenericArguments() where y == entityType select x).FirstOrDefault(); if (_methodInfo != null) { var query = _methodInfo.Invoke(EmployeeJobsContext.Instance, null); MethodInfo _typedLoadOpMethod = _loadOpMethod.MakeGenericMethod(new Type[] { entityType }); _typedLoadOpMethod.Invoke(this, new[] { query, entry.Value}); } } } private void Load&lt;T&gt;(EntityQuery&lt;T&gt; query, Expression&lt;Func&lt;T, bool&gt;&gt; where) where T: Entity { if (where != null) query = query.Where(where); EmployeeJobsContext.Instance.Load(query, (loadOp) =&gt; { EntityCount--; if (loadOp.HasError) { Errors.Add(loadOp.Error); loadOp.MarkErrorAsHandled(); } if (EntityCount == 0) _reply(new LoadEntityQueryResult { ErrorList = Errors }); }, null); } </code></pre> <p>The handler for the Load operation watches for the last entity to finish loading, then responds to the client that loading is complete (with any errors, should they occur).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload