0
我使用的OData通過Web API和得到這個錯誤:asp.net網頁API odataNo IdLink
<m:innererror>
<m:message>
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.
</m:message>
<m:type>System.InvalidOperationException</m:type>
<m:stacktrace/>
<m:internalexception>
<m:message>
No IdLink factory was found. Try calling HasIdLink on the EntitySetConfiguration for 'Tag'.
</m:message>
<m:type>System.InvalidOperationException</m:type>
這裏是我的OData配置:
config.Routes.MapODataRoute("ODataRoute", "odata", CreateModel());
static IEdmModel CreateModel()
{
var modelBuilder = new ODataModelBuilder();
modelBuilder.EntitySet<Tag>("Tag");
modelBuilder.EntitySet<Post>("Post");
return modelBuilder.GetEdmModel();
}
這裏是我的OData控制器
public class TagController : EntitySetController<Tag, int>
{
private readonly IUnitOfWork _unitOfWork;
public TagController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public override IQueryable<Tag> Get()
{
return _unitOfWork.BlogTagQueries.GetAllTags().AsQueryable();
}
protected override Tag GetEntityByKey(int key)
{
return _unitOfWork.BlogTagQueries.GetTagById(key);
}
}
任何人都可以請告訴我,爲什麼我得到這個錯誤?
它爲我工作,因爲我有一個集合,我需要URI查詢。 – Maxymus