-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Initializing a non-entity ref type in select creates a single instance for every record #12274
Comments
We observed that if the constructor is called with different parameter values for every record (e.g. with some data from the record) we get the expected beahvior: different instance created for every record. |
Duplicate of #7983 |
|
Thanks for pointing me to #7983. |
Note from triage: we will reconsider this, perhaps pivoting on whether or no the call to new is in the final projection. Also, Relinq makes this problematic because it erases the New expression. |
We have done work to now create parameter for NewExpression query tree. So this should likely be fixed. |
Consider the following entity type and its DTO type.
Now query all the entities and project them to the DTO type.
We would expect that a new IDCard instance will be created for each DogDTO - as this is what would happen in case of LINQ-to-Objects.
However, the constructor of IDCard is called only once and the IDCard instance will be the same for all DogDTOs.
There is a full repro repo here.
Further technical details
EF Core version: 2.1.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows Server 2016
IDE: Visual Studio 2017 15.7
The text was updated successfully, but these errors were encountered: