无法从微风中获取元数据,发生错误

时间:2015-02-11 04:04:02

标签: breeze

我正在尝试使用微风开发某种计算器,以便在计算用户是否想保存数据时,他/她可以将其保存到数据库中并使用breeze webapi进行显示。

我的带有敲除绑定的页面从breeze获取数据

<div id="calculatorList">
    <table class="table table-striped">
        <tbody data-bind="foreach: calculate">
            <tr>
                <td data-bind="text: FirstNumber"></td>
                <td data-bind="text: Operator"></td>
                <td data-bind="text: SecondNumber"></td>
                <td data-bind="text: Output"></td>
                <td>
                    <button data-bind="click: editCalculate" class="btn btn-primary">Edit</button>
                </td>
                <td>
                    <button data-bind="click:deleteCalculate" class="btn btn-primary">Delete</button>
                </td>
            </tr>
        </tbody>
    </table>
</div>

我的DbContext cs文件

public class ResultDbContext : DbContext
{
    public ResultDbContext() : base("DefaultConnection")
    {
            Database.SetInitializer<ResultDbContext>(null);
    }
    public DbSet<Result> Results { get; set; }
}

控制器

[BreezeController]
public class CalculatorController : ApiController
{
    readonly EFContextProvider<ResultDbContext> _cp = new EFContextProvider<ResultDbContext>();

    [HttpGet]
    public string Metadata()
    {
        return _cp.Metadata();
    }

    [HttpGet]
    public IQueryable database()
    {
        return _cp.Context.Results;
    }

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {

        return _cp.SaveChanges(saveBundle);
    }
}

但我仍然收到以下错误

{"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"Method not found: 'System.Data.Objects.ObjectContext System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()'.","ExceptionType":"System.MissingMethodException","StackTrace":"   at Breeze.WebApi.EFContextProvider`1.GetMetadataFromDbContext(Object context)\r\n   at Breeze.WebApi.EFContextProvider`1.GetMetadataFromContext(Object context)\r\n   at Breeze.WebApi.EFContextProvider`1.BuildJsonMetadata()\r\n   at Breeze.WebApi.ContextProvider.Metadata()\r\n   at SpaCalculator.Controllers.CalculatorController.Metadata() in c:\\Users\\arajak\\Documents\\Visual Studio 2012\\Projects\\Calculator\\SpaCalculator\\Controllers\\CalculatorController.cs:line 22\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}

任何人都可以说出这个错误发生的原因

0 个答案:

没有答案