我将 Odata 与 web api 一起使用并收到此错误:
<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);
}
}
谁能告诉我,为什么我会收到这个错误?