You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am using PredicateBuilder to create a custom filter in my application.
If I add a filter with a navigation property, I have an InvalidOperationException
The LINQ expression 'DbSet<Announcement>
.Join(
outer: DbSet<AutoPart>,
inner: a => EF.Property<Nullable<Guid>>(a, "AutoPartId"),
outerKeySelector: a0 => EF.Property<Nullable<Guid>>(a0, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<Announcement, AutoPart>(
Outer = o,
Inner = i
))
.Join(
outer: DbSet<VehicleModel>,
inner: a => EF.Property<Nullable<Guid>>(a.Outer, "VehicleModelId"),
outerKeySelector: v => EF.Property<Nullable<Guid>>(v, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<TransparentIdentifier<Announcement, AutoPart>, VehicleModel>(
Outer = o,
Inner = i
))
.Where(a => !(a.Outer.Outer.IsDeleted) && (int)a.Outer.Outer.Status == 0 && a.Outer.Outer.Title.ToString().ToLower().Contains(__ToLower_0) || a.Outer.Inner.Description.ToString().ToLower().Contains(__ToLower_0) || a.Inner.Description.ToString().ToLower().Contains(__ToLower_0))' 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(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
It's my code:
var predicate = PredicateBuilder.New<Announcement>(x => !x.IsDeleted && x.Status == Enums.AnnouncementStatus.Listed);
predicate.And(x => x.Title.ToString().ToLower().Contains(filter["term"].ToString().ToLower())
//if I remove this list everything works
|| x.AutoPart.Description.ToString().ToLower().Contains(filter["term"].ToString().ToLower()) ||x.VehicleModel.Description.ToString().ToLower().Contains(filter["term"].ToString().ToLower())
);
var announcements = this.DbContext.Set<Announcement>()
.AsExpandableEFCore()
.Include(x => x.AutoPart)
.Include(x => x.VehicleModel)
.Where(predicate)
.OrderByDescending(x => x.PostDate)
.Skip(Math.Max(pageIndex - 1, 0) * pageSize)
.Take(pageSize);
Hi,
I am using PredicateBuilder to create a custom filter in my application.
If I add a filter with a navigation property, I have an InvalidOperationException
It's my code:
if I remove:
and
everything works normally
Environment:
NetCore 3.1
LinqKit.Microsoft.EntityFrameworkCore 3.0.0
Microsoft.EntityFrameworkCore 3.1.4
Tanks
The text was updated successfully, but these errors were encountered: