Code: Select all
.
[ResponseType(typeof(IEnumerable<Order>))]
public async Task<IHttpActionResult> GetOrders()
{
try
{
IEnumerable<Order> entities = await _dbContext.Orders
// TODO: Add Includes for reference and/or collection properties
.ToListAsync();
return Ok(entities);
}
catch
{
return null;
}
}
at System.Data.Entity.Core.EntityKey.AddHashValue(Int32 hashCode, Object keyValue)
at System.Data.Entity.Core.EntityKey.GetHashCode()
at System.Collections.Generic.GenericEqualityComparer`1.GetHashCode(T obj)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Data.Entity.Core.Objects.ObjectStateManager.TryGetEntityEntry(EntityKey key, EntityEntry& entry)
at System.Data.Entity.Core.Objects.ObjectStateManager.FindEntityEntry(EntityKey key)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.<MoveNextAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<ForEachAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TrackableWebApi1.WebApi.Controllers.OrderController.<GetOrders>d__0.MoveNext() in c:\Users\kylel\OneDrive\Documents\Visual Studio 2013\Projects\TrackableWebApi1\TrackableWebApi1\TrackableWebApi1.WebApi\Controllers\OrderController.cs:line 28
Keep in mind that this code works correctly:
Code: Select all
// GET api/Order/5
[ResponseType(typeof(Order))]
public async Task<IHttpActionResult> GetOrder(int id)
{
Order entity = await _dbContext.Orders
// TODO: Add Includes for reference and/or collection properties
.SingleOrDefaultAsync(e => e.OrderID == id);
if (entity == null)
{
return NotFound();
}
return Ok(entity);
}
In the "public async Task<IHttpActionResult> GetOrders()" if I hover over _dbcontext and try and to expand orders it gives an error "command out of sync". However, if I do the exact same thing in "public async Task<IHttpActionResult> GetOrder(int id)" it expand the orders correctly.