[EF-66] ShadowProperty of type ObjectId is unsupported Created: 15/Oct/23  Updated: 20/Oct/23  Resolved: 20/Oct/23

Status: Closed
Project: Entity Framework
Component/s: None
Affects Version/s: Public Preview 1
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Bill Richards Assignee: James Kovacs
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates EF-42 Shadow properties Backlog

 Description   

If an Entity is defined without an Id or _id property, and a Shadow Property is defined as part of the OnModelCreating method

modelBuilder.Entity<ModelType>().Property<ObjectId>("Id");

System.NotSupportedException is thrown at runtime 

System.NotSupportedException: 'Unsupported shadow property 'TempId' identified on entity type 'ModelType'.'

It can be desirable to have the entity identifier implemented as a shadow property to enable models to be easily ported between SqlServer and MongoDB, for example.

For MongoDB

modelBuilder.Entity<ModelType>().Property<ObjectId>("Id"); 

For SqlServer

modelBuilder.Entity<ModelType>().Property<uint>("Id");

 



 Comments   
Comment by James Kovacs [ 20/Oct/23 ]

Hi, bill@greyskin.co.uk,

Thank you for trying out Public Preview 1 of our EF Core Provider for MongoDB. Public Preview 1 does not implement support for shadow properties as noted in the Limitations & Roadmap.

Id (which is serialized as _id in the database) is a required field for all documents stored in MongoDB as it represents the unique identifier for a document and serves the same purpose as a primary key in a relational database. While _id defaults to ObjectId, it can be any scalar type (int, string, GUID, etc.) or even a compound key.

We may decide to add support for shadow properties in a future version.

Sincerely,
James

Generated at Thu Feb 08 08:26:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.