【问题标题】:OData with Mongo: System.ArgumentException: 'The property 'Id' on type 'Item' must be a Complex property. (Parameter 'propertyInfo')'带有 Mongo 的 OData:System.ArgumentException:'Item' 类型上的属性 'Id' 必须是复杂属性。 (参数'propertyInfo')'
【发布时间】:2022-01-12 12:22:18
【问题描述】:

我正在尝试使用ODataMongo 配置.net core

我收到此错误: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;
}

【问题讨论】:

    标签: c# mongodb .net-core odata


    【解决方案1】:
    public abstract class Document : IDocument
    {
        //...
        public string IdStr => Id.ToString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 2014-11-09
      • 2020-03-27
      • 2021-06-11
      • 2015-05-17
      相关资源
      最近更新 更多