我正在尝试在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_mongoCrud; public AppointmentController() { _mongoCrud = new MongoCrud (); } [EnableQuery] public IQueryable GetAppointment() { return _mongoCrud.GetAllEntities(); } }
路由:
public static void Register(HttpConfiguration config) { // Web API configuration and services ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet("Appointment").EntityType.HasKey(p => p.Id); config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: null, model: builder.GetEdmModel()); ); }
当我运行项目时,会引发以下异常:
Id
type上的属性SaveMyDate.Entities.Company
必须是Navigation属性.参数名称:navigationProperty
以前有人有这个问题吗?