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

Cosmos: Adding an un-owned related entity #25167

Closed
elliotritchie opened this issue Jun 28, 2021 · 1 comment · Fixed by #26152
Closed

Cosmos: Adding an un-owned related entity #25167

elliotritchie opened this issue Jun 28, 2021 · 1 comment · Fixed by #26152
Labels
area-cosmos area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@elliotritchie
Copy link

Adding an un-owned related entity causes an exception to be thrown when SaveChanges is called:

using (var db = new BloggingContext())
{
    var blog = new Blog { Url = "http://blogs.msdn.com/adonet" };
    db.Add(blog);
    db.SaveChanges();
    blog.Posts.Add(new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
    db.SaveChanges();
}
Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: d90d9317-51d4-4e7e-8fb1-845cf6ef3ba8; Reason: (
Errors : [
  "Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
]

I'm using these workarounds for now:

using (var db = new BloggingContext())
{
    var blog = new Blog { Url = "http://blogs.msdn.com/adonet" };
    blog.Posts.Add(new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
    db.Add(blog);
    db.SaveChanges();
}
using (var db = new BloggingContext())
{
    var blog = new Blog { Url = "http://blogs.msdn.com/adonet" };
    db.Add(blog);
    db.SaveChanges();
    var post = new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" };
    blog.Posts.Add(post);
    db.Posts.Add(post);
    db.SaveChanges();
}

EF Core version: 6.0.0-preview.5.21301.9
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: .NET 5.0

@smitpatel
Copy link
Contributor

ChangeTracker marks Post entity as modified so we ends up issue ReplaceItem command which fails. Not sure why Post is not added rather than modified.

@AndriySvyryd AndriySvyryd self-assigned this Jun 29, 2021
@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Jun 29, 2021
@AndriySvyryd AndriySvyryd added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. area-model-building and removed area-save-changes labels Sep 23, 2021
@AndriySvyryd AndriySvyryd removed their assignment Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants