OData 8.2.3中NotMapped属性过滤数据失败问题求助
OData 8.2.3 未映射属性过滤异常求助
我们在使用OData 8.2.3版本时遇到问题:在Customer实体类中定义了带有[NotMapped]特性的StatusId属性(该属性为Status枚举的数值映射),并将其注册到EDM模型中。当使用LINQ基于StatusId属性过滤数据时,抛出System.InvalidOperationException异常,提示该未映射成员无法被翻译。我们尝试移除EDM模型中的相关配置,但问题仍未解决,现寻求解决方案。
相关代码
Customer实体类代码
public partial class Customer { [Newtonsoft.Json.JsonProperty("Name", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] public string Name { get; set; } [Newtonsoft.Json.JsonProperty("ShortName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string ShortName { get; set; } [Newtonsoft.Json.JsonProperty("Description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Description { get; set; } [Newtonsoft.Json.JsonProperty("Status", Required = Newtonsoft.Json.Required.Always)] public WorksWarefx.Core.Enums.RecordStatus Status { get; set; } = WorksWarefx.Core.Enums.RecordStatus.active; [NotMapped] [Newtonsoft.Json.JsonProperty("StatusId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public int StatusId { get { return (int)Status; } } }
EDM模型注册代码
StructuralTypeConfiguration<Customer> customer = builder.EntitySet<Customer>(nameof(Customer)).EntityType; customer.Property(c => c.StatusId);
抛出的异常信息
Error Name : System.InvalidOperationException Error Message : The LINQ expression 'DbSet<Customer>() .Where(s => s.StatusId == __TypedProperty_0)' could not be translated. Additional information: Translation of member `'StatusId' on entity type 'Customer' failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.` Exception Type : System.InvalidOperationException
我们曾尝试移除注册表中的"EntityType.Count().Select().Filter().OrderBy().Expand(9)"配置,但问题未得到解决。
内容的提问来源于stack exchange,提问作者Raagi Shiva
相关产品推荐
相关产品推荐

