簡體   English   中英

帶有 Mongo 的 OData:System.ArgumentException:'Item' 類型上的屬性 'Id' 必須是復雜屬性。 (參數'propertyInfo')'

[英]OData with Mongo: System.ArgumentException: 'The property 'Id' on type 'Item' must be a Complex property. (Parameter 'propertyInfo')'

我正在嘗試使用ODataMongo配置.net core

我收到此錯誤: System.ArgumentException: 'The property 'Id' on type 'Item' must be a Complex property. (Parameter 'propertyInfo')' System.ArgumentException: 'The property 'Id' on type 'Item' must be a Complex property. (Parameter 'propertyInfo')'

這是我的配置:

services.AddControllers(options =>
            {
               // something here
            })
            .AddOData(opt =>
            {
                opt.Count()
                    .Filter()
                    .Expand()
                    .Select()
                    .OrderBy()
                    .SetMaxTop(5000)
                    .AddRouteComponents("odata", GetEdmModel());

                opt.TimeZone = TimeZoneInfo.Utc;
            });

public static IEdmModel GetEdmModel()
    {
        var builder = new ODataConventionModelBuilder();

        var entitySetConfiguration = builder.EntitySet<Item>("Item");
        entitySetConfiguration.EntityType.HasKey(entity => entity.Id);

        return builder.GetEdmModel();
    }

我的實體:

public class Item : Document
{
    public string SubCategory { get; set; }
    public string ProductCode { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public abstract class Document : IDocument
{
    public ObjectId Id { get; set; }

    public DateTime CreatedAt => Id.CreationTime;
}
public abstract class Document : IDocument
{
    //...
    public string IdStr => Id.ToString();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM