C#:Net Core 3.1 包含 Linq 导致客户端异常错误 [英] C#: Net Core 3.1 Contains Linq causes Client Side Exception Error
问题描述
以下是在 Net Core 3.1 中引发客户端异常错误
不知道为什么,PropertyIdentifier 在 Property Entity Data 表和类中.
有人知道怎么解决吗?
public async Task>GetByPropertyIdentifier(List identifiers){var 属性 = await _dataContext.Property.Where(x => identifiers.Contains(x.PropertyIdentifier)).ToListAsync();返回 properties.Select(_mapper.Map);}
<块引用>
错误:错误:"无效请求:LINQ 表达式 'DbSet.Where(p => __identifiers_0.Contains(p.PropertyIdentifier))' 无法翻译.以可翻译的形式重写查询,或通过插入对 AsEnumerable()、AsAsyncEnumerable()、ToList() 或 ToListAsync() 的调用显式切换到客户端评估.
资源:(但是没有调用不同的)*也不想要强制客户端评估的解决方案,因为它的查询很大
请将标识符更改为可枚举.下面的这个资源是不正确的.将其转换为 Enumerable 以进行标识符工作.投射到列表对我不起作用.
EF Core 3 x.Contains() 在表达式中,其中 x 是 ICollection
public async Task>GetByPropertyIdentifier(List identifiers){var identifiersEnumerable = identifiers.AsEnumerable();var 属性 = await _dataContext.Property.Where(x => identifiersEnumerable.Contains(x.PropertyIdentifier)).ToListAsync();返回 properties.Select(_mapper.Map);}
The following is throwing a Client Side Exception error in Net Core 3.1
Not sure why, PropertyIdentifier is in Property Entity Data table and class.
Does anyone know how to fix?
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);
}
Error: error: "Invalid request: The LINQ expression 'DbSet .Where(p => __identifiers_0.Contains(p.PropertyIdentifier))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
Resource: (No distinct is being called however) *Also do not want solution which forces client side evaluation, since its large query
EF Core 3.1 throws an exception for Contains
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);
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() in expression where x is 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 导致客户端异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!