Can't Fetch Metadata from breeze ,error occurred

隐身守侯 提交于 2019-12-12 06:19:16

问题


I am trying to develop some sort of calculator using breeze so that while calculating if user wanna save the datails he/she can save it into database and can display using breeze webapi.

My page with knockout bindings to get data from 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>

My DbContext cs file

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

Controller

[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);
    }
}

But still I am getting this following error

{"$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()"}

Can anyone will say why this error is occurring

来源:https://stackoverflow.com/questions/28446415/cant-fetch-metadata-from-breeze-error-occurred

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!