You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to save an entity by assigning same objects to two properties, but it fails to save and throws error. Database: Azure CosmosDB
With the below code, I am not able to save:
Orderorder=newOrder(){id=Guid.NewGuid().ToString(),Description="Order#1"};Productproduct=newProduct(){SKU="one",Description="this is product one"};order.Product1=product;order.Product2=product;
stack traces
System.InvalidOperationException: Unable to track an entity of type 'Order.Product2#Product' because its primary key property 'Orderid' is null.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NullableKeyIdentityMap`1.Add(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.SetEntityState(InternalEntityEntry entry, EntityState entityState)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)
at CosmosDbApi.Controllers.OrdersController.PostOrder(Order order1) in D:\Learnings\Cosmos DB\CosmosClient\CosmosDbApi\Controllers\OrdersController.cs:line 99
With the below code, I am able to save:
Orderorder=newOrder(){id=Guid.NewGuid().ToString(),Description="Order#1"};Productproduct1=newProduct(){SKU="one",Description="this is product one"};Productproduct2=newProduct(){SKU="one",Description="this is product one"};order.Product1=product1;order.Product2=product2;
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered:
I am trying to save an entity by assigning same objects to two properties, but it fails to save and throws error.
Database: Azure CosmosDB
With the below code, I am not able to save:
stack traces
With the below code, I am able to save:
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered: