无法在www.example.com中翻译LINQasp.net

mxg2im7a  于 2022-12-06  发布在  .NET
关注(0)|答案(1)|浏览(119)

我得到这个错误。

var query = DbContext.Registries.AsNoTracking().ProjectTo<Registry>(Mapper.ConfigurationProvider);
        if (onlyMine) {
            query = from registry in DbContext.Registries.AsNoTracking()
                    join member in DbContext.RegistryMembers.AsNoTracking() on registry.Id equals member.RegistryId into members
                    from membership in members.DefaultIfEmpty()
                    where onlyMine && membership.MemberId == userId
                    select new Registry {
                        Id = registry.Id,
                        Customer = new Customer {
                            Id = registry.Customer.Id,
                            Name = registry.Customer.Name,
                        },
                        Title = registry.Title,
                        Membership = membership.Role
                    };
        }
        if (!string.IsNullOrWhiteSpace(options.Search)) {
            var term = options.Search.Trim().ToLowerInvariant();
            query = query.Where(x => x.Title.ToLower().Contains(term) ||  x.Customer.Name.ToLower().Contains(term));
        }
        return await query.ToResultSetAsync(options);

我得到以下错误
系统操作无效异常:LINQ表达式'DbSet .LeftJoin(外部:数据集,内部:d =〉EF。属性(d,“客户ID”),外部键选择器:属性(d 0,“Id”),内部键选择器:(o,i)=〉新的透明标识符〈数据库注册表,数据库客户〉(外部= o,内部= i))。OrderBy(d =〉EF。属性(d.内部,“Id”)== null?null:无法翻译新客户{ Id = d.Inner.Id,Name = d.Inner.Name } .Name)“。请以可翻译的形式重写查询,或者通过插入对AsEnumerable()、AsAsyncEnumerable()、ToList()或ToListAsync()的调用来显式切换到客户端计算。

6uxekuva

6uxekuva1#

var query = DbContext.Registries.AsNoTracking().ProjectTo<Registry>(Mapper.ConfigurationProvider);
    if (onlyMine) {
        query = from registry in DbContext.Registries.AsNoTracking()
                join member in DbContext.RegistryMembers.AsNoTracking() on registry.Id equals member.RegistryId into members
                from membership in members.DefaultIfEmpty()
                where onlyMine && membership.MemberId == userId
                select new Registry {
                    Id = registry.Id,
                    Customer = new Customer {
                        Id = registry.Customer.Id,
                        Name = registry.Customer.Name,
                    },
                    Title = registry.Title,
                    Membership = membership.Role
                };
    } else if (isVendor) {
        query = from registry in DbContext.Registries.AsNoTracking()
                join member in DbContext.RegistryMembers.AsNoTracking() on registry.Id equals member.RegistryId into members
                from membership in members.DefaultIfEmpty()
                select new Registry {
                    Id = registry.Id,
                    Customer = new Customer {
                        Id = registry.Customer.Id,
                        Name = registry.Customer.Name,
                    },
                    Title = registry.Title,
                    Membership = membership.Role
                };
    }
    if (!string.IsNullOrWhiteSpace(options.Search)) {
        var term = options.Search.Trim().ToLowerInvariant();
        query = query.Where(x => x.Title.ToLower().Contains(term) ||  x.Customer.Name.ToLower().Contains(term));
    }
    return await query.ToResultSetAsync(options);

相关问题