下面是我的模型的架构:
$(document).ready(function(){
$('#last-slide').on('click', function(){
// ...
});
});
以下是我的实体映射:
{
"id": "5dd673d9-2104-4ebe-a56b-5b92ef36739b",
"InvName": "Demo Inv Name",
"ObsCollection": [
{
"ObsId": "52d673d9-2104-4ebe-a56b-5b92ef36739b",
"InvId": "5dd673d9-2104-4ebe-a56b-5b92ef36739b",
"ObsName": "Demo!"
}
],
"CV": {
"CodeId": 401,
"Value": "Demo Value for CV"
},
"Owner": {
"UserId": "abc",
"Name": "ABC DEF"
}
}
我的GET控制器方法是:
public override void Configure(EntityTypeBuilder<Inv> builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
#region Container
builder.ToContainer("Inv");
#endregion
#region PartitionKey
builder.HasPartitionKey(o => o.Id);
#endregion
#region PropertyNames
builder.Property(prop => prop.Id).ToJsonProperty("id");
#endregion
builder.HasNoDiscriminator();
builder.HasKey(p => p.Id);
builder.OwnsOne(property => property.Owner);
builder.OwnsOne(property => property.CV);
builder.OwnsMany(p => p.ObsCollection, a=> {
a.WithOwner().HasForeignKey("OwnerId");
a.HasKey("ObsId");
});
}
我的_investigationService.GetAllInvestigationsAsync方法包含:
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<Inv>), 200)]
public IActionResult Get(ODataQueryOptions<Inv> opts)
{
var investigations =
_investigationService
.GetAllInvestigationsAsync(opts);
return Ok(investigations);
}
最后我的存储库是:
public IQueryable GetAllInvestigationsAsync(ODataQueryOptions<Inv> options)
{
try
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
// This is a workaround for a limitation in EFCore. EFCore translates
// PageSize to .Top<T>() LINQ query. Adding $top to the query introduces
// another .Top<T>() LINQ query. When this LINQ (.Top<T>().Top<T>())
// get translated, the resulting SQL statement becomes invalid.
ODataQuerySettings settings = new ODataQuerySettings()
{
PageSize = options.Top == null ? 100 : options.Top.Value
};
// We are ignoring the Top, because the Page Size already account for
// the top.
AllowedQueryOptions ignoredQueryOptions = AllowedQueryOptions.Top;
var results =
options.ApplyTo(
_repository
.GetAllAsync(),
settings,
ignoredQueryOptions);
return
results;
}
catch (Exception ex)
{
_logger.LogError(ex, "Investigation Service Error - GetInvestigationsAsync: {Message}", ex.Message);
throw;
}
}
当我尝试对网址进行GET操作时:
https://localhost:5003/odata/Invs?$ expand = ObsCollection
以下是我得到的错误:
LINQ表达式'o0'无法翻译。以一种可以翻译的形式重写查询,或者通过插入对AsEnumerable(),AsAsyncEnumerable(),ToList()或ToListAsync()的调用来显式切换到客户端评估。有关更多信息,请参见https://go.microsoft.com/fwlink/?linkid=2101038。
到目前为止,我已经可以使用“选择”,“过滤”,“跳过”和“热门”。我需要扩展工作方面的帮助。