Odata 控制器 returns 未完成结果。 (电火花机模型)
Odata controller returns not complete result. (EDM model)
场景
我在 EFcontext 中定义了一些名为 Category 的实体。它是干净的 POCO class。在 EFContext OnModelCreating 方法中,我应用实体配置。在我的初创公司中,我为我的查询配置了 Odata,并基于 Conventional Builder 构建了 EDM 模型。我的控制器继承自 ODataController,具有 ODataRoutePrefix、OdataRoute 和 EnableQuery属性。
问题
在我收到的回复中:
{
"@odata.context": "https://localhost:44362/api/odata/$metadata#Categories",
"value": [
这不是错误。它以“[”结尾。没有错误。 http状态:200
odata 配置
app.UseMvc(options =>
{
options.EnableDependencyInjection();
options.Select().Filter().OrderBy().Count().Expand().MaxTop(100).SkipToken();
options.MapODataServiceRoute("odata", "api/odata", GetEdmModel());
});
private static IEdmModel GetEdmModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
var category = builder.EntitySet<Category>("Categories");
category.EntityType.HasKey(c => c.Id);
return builder.GetEdmModel();
}
EF 类别类型配置
public void Configure(EntityTypeBuilder<Category> categoryConfiguration)
{
categoryConfiguration.ToTable("Categories", QueryEFContext.DefaultSchema);
categoryConfiguration.HasKey(category => category.Id);
categoryConfiguration.Property(category => category.Name).IsRequired();
categoryConfiguration.Property(category => category.Color).IsRequired();
}
尝试过
它 returns 当我删除行时的正确响应:
modelBuilder.ApplyConfiguration(new CategoryTypeConfiguration());
这个bug我遇到过一次。在我的例子中,它发生是因为 Entity Framework 中发生了错误,但服务返回了 200 OK
。
要查看您的应用程序是否属于这种情况,您可以配置 Visual Studio 以中断所有异常:
- 点击:调试
->
Windows->
异常设置(Ctrl
+Alt
+E
)
- 检查:'Common Language Runtime Exceptions'
然后重新发送你的请求,看看是否弹出任何异常。
场景
我在 EFcontext 中定义了一些名为 Category 的实体。它是干净的 POCO class。在 EFContext OnModelCreating 方法中,我应用实体配置。在我的初创公司中,我为我的查询配置了 Odata,并基于 Conventional Builder 构建了 EDM 模型。我的控制器继承自 ODataController,具有 ODataRoutePrefix、OdataRoute 和 EnableQuery属性。
问题
在我收到的回复中:
{
"@odata.context": "https://localhost:44362/api/odata/$metadata#Categories",
"value": [
这不是错误。它以“[”结尾。没有错误。 http状态:200
odata 配置
app.UseMvc(options =>
{
options.EnableDependencyInjection();
options.Select().Filter().OrderBy().Count().Expand().MaxTop(100).SkipToken();
options.MapODataServiceRoute("odata", "api/odata", GetEdmModel());
});
private static IEdmModel GetEdmModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
var category = builder.EntitySet<Category>("Categories");
category.EntityType.HasKey(c => c.Id);
return builder.GetEdmModel();
}
EF 类别类型配置
public void Configure(EntityTypeBuilder<Category> categoryConfiguration)
{
categoryConfiguration.ToTable("Categories", QueryEFContext.DefaultSchema);
categoryConfiguration.HasKey(category => category.Id);
categoryConfiguration.Property(category => category.Name).IsRequired();
categoryConfiguration.Property(category => category.Color).IsRequired();
}
尝试过
它 returns 当我删除行时的正确响应:
modelBuilder.ApplyConfiguration(new CategoryTypeConfiguration());
这个bug我遇到过一次。在我的例子中,它发生是因为 Entity Framework 中发生了错误,但服务返回了 200 OK
。
要查看您的应用程序是否属于这种情况,您可以配置 Visual Studio 以中断所有异常:
- 点击:调试
->
Windows->
异常设置(Ctrl
+Alt
+E
) - 检查:'Common Language Runtime Exceptions'
然后重新发送你的请求,看看是否弹出任何异常。