yae*_*ael 8 c# odata asp.net-web-api
我正在尝试在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();
}
}
Run Code Online (Sandbox Code Playgroud)
路由:
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());
);
}
Run Code Online (Sandbox Code Playgroud)
当我运行项目时,会引发以下异常:
Idtype上的属性SaveMyDate.Entities.Company必须是Navigation属性.参数名称:navigationProperty
以前有人有这个问题吗?
| 归档时间: |
|
| 查看次数: |
291 次 |
| 最近记录: |