Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MemberMemberBinding #16867

Open
roji opened this issue Jul 31, 2019 · 8 comments
Open

Support MemberMemberBinding #16867

roji opened this issue Jul 31, 2019 · 8 comments

Comments

@roji
Copy link
Member

roji commented Jul 31, 2019

This tracks adding support for MemberMemberBinding in our query pipeline (first discussed in #16791).

Some preliminary work was done and is available in https://github.com/roji/EntityFrameworkCore/tree/MemberMemberBinding.

@erdalsivri
Copy link

Do you happen to have an approximate timeline for this feature request? And do you plan to support MemberListBinding?

We are using protobuf-generated C# classes as DTOs and having trouble projecting to repeated fields (i.e., lists) due to RepeatedField<T> fields not having setters:

context.Users.Select(u => new UserProto {
  Roles = {
    u.Roles.Select(...),
  },
}).ToList();

This doesn't work due to EFCore not supporting MemberListBinding IIUC

@ajcvickers
Copy link
Member

@erdalsivri We use votes (👍) on issues as a rough measure of customer demand for issues, which then feeds into the planning process. This issue doesn't have any votes, which means there are more than 500 issues ahead of it in the voting.

@auvansang
Copy link

Do you happen to have an approximate timeline for this feature request? And do you plan to support MemberListBinding?

We are using protobuf-generated C# classes as DTOs and having trouble projecting to repeated fields (i.e., lists) due to RepeatedField<T> fields not having setters:

context.Users.Select(u => new UserProto {
  Roles = {
    u.Roles.Select(...),
  },
}).ToList();

This doesn't work due to EFCore not supporting MemberListBinding IIUC

I have same issue with you LOL

@auvansang
Copy link

auvansang commented Oct 4, 2023

Currently, I found the work around solution:

I create use partial class with the same name from the generated.
Then I create a new constructor that accept the tag list args.

public sealed partial class PostResponse
{
    public PostResponse(IEnumerable<string> tags): base()
    {
        Tags.AddRange(tags);
    }
}

And the projection will look like bellow:

x => new PostResponse(x.TagSlugs)
  {
      Id = x.Id.ToString(),
      Title = x.Title,
      Slug = x.Slug,
      Excerpt = x.Excerpt,
      Content = x.Content,
  }

you can also use the constructor like bellow, but it will cause of getting all columns

public PostResponse(IEnumerable<Tag> tags) : base()
{
    Tags.AddRange(tags.Select(x => x.Slug));
}

@jsheetzmt
Copy link

Do you happen to have an approximate timeline for this feature request? And do you plan to support MemberListBinding?

We are using protobuf-generated C# classes as DTOs and having trouble projecting to repeated fields (i.e., lists) due to RepeatedField<T> fields not having setters:

context.Users.Select(u => new UserProto {
  Roles = {
    u.Roles.Select(...),
  },
}).ToList();

This doesn't work due to EFCore not supporting MemberListBinding IIUC

Running into the same use-case with auto generated gRPC classes

@russcam
Copy link

russcam commented Oct 17, 2024

Using the approach outlined in #16867 (comment), was working fine in EF Core 8, but now throws an exception in EF Core 9 RC

var entities= await dbContext.Entities
    .AsNoTracking()
    .Skip(pageIndex * pageSize)
    .Take(pageSize)
    .OrderBy(a => a.Prop1)
    .Select(a => new Protobuf.Entity(a.Values.Select(v => v.LinkedEntity.Name!))
    {
        Prop1= a.Prop1,
        Prop2 = a.Prop2 ,
    })
    .ToListAsync();

exception thrown

System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method1969(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)

versions in Directory.Package.props

<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.0-rc.2.24474.1"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0-rc.2.24474.1"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.0-rc.2.24474.1"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0-rc.2.24474.1"/>
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.2"/>

@roji
Copy link
Member Author

roji commented Oct 17, 2024

Hey @russcam 👋

MemberMemberBinding should indeed be working in the final select (client evaluation), this issue is more about enabling it in other contexts... If EF 9 regressed support for this, that's probably something we should look at - can you please open a separate issue with a minimal repro?

@russcam
Copy link

russcam commented Oct 18, 2024

Apologies for conflating @roji, I've opened #34934 with a minimal repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants