-
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
EF core 3.1.1 - owned entity proxy problem #20213
Comments
Instead of initializing it always set it in the getter if null. Duplicate of #18007 |
it will not solve problem with proxy not capturing changes ! |
@PospisilBohumir The lazy loading proxies don't capture changes they just handle lazy loading. And if you make the change suggested above your test passes: public class TestEntity
{
public long Id { get; set; }
private TestOwnedEntity _testOwnedEntity;
public virtual TestOwnedEntity TestOwnedEntity
{
get
{
if (_testOwnedEntity == null)
{
_testOwnedEntity = new TestOwnedEntity();
}
return _testOwnedEntity;
}
private set { _testOwnedEntity = value; }
}
} |
it seems to be working ... thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently struggle with strange problem in EF core 3.1.1. We are trying to migrate from EF6 to EF core and Owned entities behave differently then Complex types in EF6. When owned entity is initialized by empty object then EF fails to detect change. This problem is occuring just against MSSQL, against "In memory" database everything seems to be fine.
In this example context should detect change. "In memory database" detects it correctly, but MS Sql provider fails to detect it. It is most likely caused by missing Proxy around owned type. Proxy is missing when all properties of owned type are default and without initialization the owned entity is null.
Could you please give me some tip how to setup it correctly? I don't want to remove default initialization of owned entities, it would force us to check everywhere if Owned entity is null or not.
Whole project is on github
Further technical details
EF Core version: 3.1.2
Database provider: SqlServer
Target framework: core 3.1
Operating system: Windows
The text was updated successfully, but these errors were encountered: