问题
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);
回答1:
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);
}
来源:https://stackoverflow.com/questions/62802339/c-net-core-3-1-contains-linq-causes-client-side-exception-error