Expression Visitor access property on parameter representing local variable

Trying to write an ExpressionVisitor that would rewrite a query

Starting point

var contractSubjectKey = new ContractSubjectKey(subjectId, rank);

insurance = context.Set<Insurance>()
    .FirstOrDefault(i => i.Key.ContractSubjectKey == contractSubjectKey);

After rewrite expected

i => i.Key.ContractSubjectKey.Id == contractSubjectKey.Id

I’m trying to rewrite BinaryExpression here so it goes and compares properties itself.
The left side of operation I think i got covered. Initial left side of BinaryExpression is MemberExpression.

var left = Expression.Property(memberExpression, "Id");

So I just access property itself.

In case i use for right side ConstantExpression

var right = Expression.Constant(1, typeof(int));

so the resulting operation looks like

i.Key.ContractSubjectKey.Id == 1

it gets translated to SQL no problem, and retrieves data.

I do have problem with the right side. Right side is ParameterExpression. Parameter values I cannot find anywhere in initial Expression or QueryExpressionEventData (working with IQueryExpressionInterceptor). Not sure I understand it fully. It represents a local variable, evaluates during translation, something close to constant?

Anyway, if i try PropertyExpression

var right = Expression.Property(parameterExpression, "Id");

it seems i get proper looking expression, but during translation it fails
`The Linq expression …. could not be translated

System.InvalidOperationException : The LINQ expression ‘DbSet()
.Where(i => EF.Property(EF.Property(i, “Key”), “ContractSubjectKey”).Id == __contractSubjectKey_0.Id)’ 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’.

So problem is somewhere in evaluation value for Id on local variable?

Tried many things… not gonna waste space here.

One additional piece of context

public record ContractSubjectKey(int Id, int Rank);

//insurance.Key.ContractSubjectKey is actually ContractSubjectKeyInsurance which inherits from ContractSubjectKey
public record ContractSubjectKeyInsurance : ContractSubjectKey
{
    public ContractSubjectKeyInsurance(int Id, int Rank) : base(Id, Rank)
    {

    }
    public ContractSubjectKeyInsurance(int Id, int Rank, int InsuranceKeyId) : base(Id, Rank)
    {
        _insuranceKeyId = InsuranceKeyId;
    }

    private int _insuranceKeyId;
}

public record InsuranceKey(int Id, ContractSubjectKey ContractSubjectKey)    
{
    this.Id = Id;
    _contractSubjectId = ContractSubjectKey.Id;
    _contractSubjectRank = ContractSubjectKey.Rank;
    this.ContractSubjectKey = 
       new ContractSubjectKeyInsurance(ContractSubjectKey.Id,  ContractSubjectKey.Rank, Id);
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật