-
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
Cosmos: id not populated on Attach #15289
Comments
Note that the comment on line 55 of |
What's interesting is that it seems that the exception will occur even if just attaching the entity to the context. |
Just completed a sanity check against a demonstration from a blog post online, and the same issue arises. I should probably also ask if it is legitimately invalid to simply introduce a model instance out of the blue and attach it to a context with the intent of removing it. |
Apparently, the issue is that because the |
Same behaviour is experienced with latest nightly build. |
Apparently, if the entity is simply reloaded via using |
This is still an issue in the latest build from the |
@TheFanatr Instead of calling var itemEntry = context.Entry(createdItem);
itemEntry.Property<string>("id").CurrentValue = "Item|" + createdItem.ID;
itemEntry.State = EntityState.Deleted; We'll investigate whether this value can be generated automatically for non-add scenarios in the future. |
@AndriySvyryd Thank you for providing this workaround, however I am still a little frustrated. The value used to be generated correctly for deletion as long as public string id { get; set; } = Guid.NewGuid().ToString();
It feels as though this functionality is not yet implemented, but no exceptions are being thrown. Am I using these features incorrectly? I should also mention that I was aware of the provided workaround beforehand but considered it to be inadequate as I believed I was simply using the APIs incorrectly, but if it is currently the most appropriate solution then so be it. |
@TheFanatr I'll also investigate why Reload stopped working. What problems did you run into when setting |
Related: #16186 |
For Attach to work we need to generate key values: #13575 |
I have a fix implemented on a local copy of the master branch via inheriting |
This is messy because it does not account for other values that are generated, and more specifically, making sure that those generators don't run and replace existing data. But as for generating the shadow properties required for the Cosmos DB provider to work correctly, this suffices for me as it also fixes the problem of |
I've never touched the source to Entity Framework Core in my life so this took some long hours (15+) of debugging; maybe it should be more clear somewhere that this provider is not to be used in it's current state. To further back that up, I've now found that loading reference navigation properties does not work and will post an issue soon enough. |
@TheFanatr |
I did try with the nightly builds on the 30th, and it did not work. I set up a reproduction project and just debugged it myself with the Entity Framework Core source from master. I can post it if you would like. |
The failure mode was an exception saying that the model was not finalized, but I know that it was and even finalized it manually to see if it could be fixed that way. |
@TheFanatr If |
Ok, sounds good. Just tested at 1:38 PM with latest master alpha release |
…ed value if it is incorrectly empty when entity tracking state changes occur. This is done via the creation and provisioning of a custom state manager (IStateManager) service containing the logic.
… From Detached State Fixes #15289
When trying to delete an entity created using a different database context instance than the one currently in use, an exception is thrown.
Steps to reproduce
EFCoreAzureCosmosDBExperiments.zip
CosmosContext
class to connect to whatever instance or emulator of Azure Cosmos DB you have running.Further technical details
EF Core version: 3.0.0-preview3.19153.1
Database Provider: Microsoft.EntityFrameworkCore.Cosmos
Operating system: Windows 10 1908 Build 17763.379
IDE: Visual Studio 2019 16.0.0
The text was updated successfully, but these errors were encountered: