使用WebApi的OData路由在导航问题上引发异常

时间:2015-12-12 20:00:36

标签: c# asp.net-web-api odata

我正在尝试在Web Api中启用OData。 。我创建了一个appanyment类OData路由,以及一个继承自ODataController的控制器,我想在控制器中调用我的Get方法。

代码:

public class Appointment : IMongoEntity
{
    public ObjectId Id { get; set; }
    public Company Company { get; set; }
    public DateTime Time { get; set; }
    public DateTime LastModified { get; set; }
    public string Remark { get; set; }
}

public class AppointmentController : ODataController
{
    private readonly MongoCrud<Appointment> _mongoCrud;
    public AppointmentController()
    {
        _mongoCrud = new MongoCrud<Appointment>();
    }


    [EnableQuery]
    public IQueryable<Appointment> GetAppointment()
    {
        return _mongoCrud.GetAllEntities();
    }
}

路由:

public static void Register(HttpConfiguration config)
{
    // Web API configuration and services
    ODataModelBuilder builder = new ODataConventionModelBuilder();
    builder.EntitySet<Appointment>("Appointment").EntityType.HasKey(p => p.Id);

    config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: null,
        model: builder.GetEdmModel());              
    );
}

当我运行项目时,会引发以下异常:

  

类型Id上的属性SaveMyDate.Entities.Company必须是Navigation属性。   参数名称:navigationProperty

以前有人遇到过这个问题吗?

0 个答案:

没有答案