Home > Software engineering >  .xxxxxx ?? v.Outer.Outer.xxxx)' could not be translated OrderByDescending with null conditional
.xxxxxx ?? v.Outer.Outer.xxxx)' could not be translated OrderByDescending with null conditional

Time:04-12

    public virtual DateTime? LastModificationTime { get; set; }
    public virtual DateTime CreationTime { get; set; }

Query

await vulnerabilityMappingSelect
      .OrderByDescending(x => x.LastModificationTime ?? x.CreationTime)
      .PageBy(input).ToListAsync();

Trying to filter if LastModificationTime has value then sort with LastModificationTime otherwise sort with CreationTime

Getting an exception as could not be translated as below

The LINQ expression 'DbSet<VulnerabilityMappingTemplate>()
    .Where(v => __ef_filter__p_0 || !(((ISoftDelete)v).IsDeleted) && __ef_filter__p_1 || (int?)((IMustHaveTenant)v).TenantId == __ef_filter__CurrentTenantId_2)
    .Where(v => v.TenantId == __AbpSession_TenantId_Value_0)
    .Join(
        inner: DbSet<SourceType>()
            .Where(s => __ef_filter__p_3 || !(((ISoftDelete)s).IsDeleted) && __ef_filter__p_4 || ((IMayHaveTenant)s).TenantId == __ef_filter__CurrentTenantId_5), 
        outerKeySelector: v => EF.Property<int?>(v, "SourceTypeId"), 
        innerKeySelector: s => EF.Property<int?>(s, "Id"), 
        resultSelector: (o, i) => new TransparentIdentifier<VulnerabilityMappingTemplate, SourceType>(
            Outer = o, 
            Inner = i
        ))
    .Join(
        inner: DbSet<SourceTool>()
            .Where(s0 => __ef_filter__p_6 || !(((ISoftDelete)s0).IsDeleted) && __ef_filter__p_7 || ((IMayHaveTenant)s0).TenantId == __ef_filter__CurrentTenantId_8), 
        outerKeySelector: v => EF.Property<int?>(v.Outer, "SourceToolId"), 
        innerKeySelector: s0 => EF.Property<int?>(s0, "Id"), 
        resultSelector: (o, i) => new TransparentIdentifier<TransparentIdentifier<VulnerabilityMappingTemplate, SourceType>, SourceTool>(
            Outer = o, 
            Inner = i
        ))
    .OrderByDescending(v => new VulnerabilityMappingTemplate{ 
        Id = v.Outer.Outer.Id, 
        TemplateName = v.Outer.Outer.TemplateName, 
        SourceType = v.Outer.Inner, 
        SourceTool = v.Inner, 
        VulnerabilityFieldMapping = MaterializeCollectionNavigation(
            Navigation: VulnerabilityMappingTemplate.VulnerabilityFieldMapping,
            subquery: DbSet<VulnerabilityFieldMapping>()
                .Where(v0 => __ef_filter__p_9 || !(((ISoftDelete)v0).IsDeleted) && __ef_filter__p_10 || (int?)((IMustHaveTenant)v0).TenantId == __ef_filter__CurrentTenantId_11)
                .Where(v0 => EF.Property<long?>(v.Outer.Outer, "Id") != null && object.Equals(
                    objA: (object)EF.Property<long?>(v.Outer.Outer, "Id"), 
                    objB: (object)EF.Property<long?>(v0, "VulnerabilityMappingTemplateId")))), 
        LastModifierUserId = v.Outer.Outer.LastModifierUserId, 
        CreatorUserId = v.Outer.Outer.CreatorUserId, 
        CreationTime = v.Outer.Outer.CreationTime 
    }
    .LastModificationTime ?? v.Outer.Outer.CreationTime)' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

CodePudding user response:

Problem that LastModificationTime has no defined projection. You have missed it in initialization of VulnerabilityMappingTemplate.

  • Related