问题描述
以下内容在Net Core 3.1中引发了客户端异常错误
The following is throwing a Client Side Exception error in Net Core 3.1
不确定为什么,PropertyIdentifier位于属性实体数据"表和类中.
Not sure why, PropertyIdentifier is in Property Entity Data table and class.
有人知道如何解决吗?
public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers)
{
var properties = await _dataContext.Property
.Where(x => identifiers.Contains(x.PropertyIdentifier))
.ToListAsync();
return properties.Select(_mapper.Map);
}
资源:(但是没有被调用)*由于查询量大,因此也不想强制客户端评估的解决方案
Resource: (No distinct is being called however)*Also do not want solution which forces client side evaluation, since its large query
使用Net Core 3.1
Using Net Core 3.1
public partial class Property
{
public Property()
{
AddressChangeRequest = new HashSet<AddressChangeRequest>();
CalamityEventHistory = new HashSet<CalamityEventHistory>();
CutHistoryPropertyChildProperty = new HashSet<CutHistoryProperty>();
....}
public int PropertyId { get; set; }
public int? LkPropertyTypeId { get; set; }
public int? LkZoningId { get; set;
public string PropertyIdentifier { get; set; }
....
modelBuilder.Entity<Property>(entity =>
{
entity.ToTable("Property", "PM");
entity.HasIndex(e => e.PropertyIdentifier)
.HasName("Unique_Property_PropertyIdentifier")
.IsUnique();
entity.Property(e => e.PropertyIdentifier)
.HasMaxLength(16)
.IsUnicode(false);
推荐答案
请将标识符更改为可枚举.下面的资源不正确.将其转换为Enumerable以供标识符使用是可行的.投射到列表对我不起作用.
Please Change Identifiers to Enumerable. This resource below is incorrect. Converting it to Enumerable for identifiers works. Casting to List does not work for me.
EF Core 3 x.Contains( ),其中x是ICollection
public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers)
{
var identifiersEnumerable = identifiers.AsEnumerable();
var properties = await _dataContext.Property
.Where(x => identifiersEnumerable.Contains(x.PropertyIdentifier))
.ToListAsync();
return properties.Select(_mapper.Map);
}
这篇关于C#:Net Core 3.1包含Linq导致客户端异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!