-
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 DB: Is there ANY way to currently support IDictionary<string, object> #21265
Comments
@DaleyKD Can you provide more details on where the dictionary appears in the C# model and what the expected mapping to JSON would be? |
Ideally: public class Foo
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[JsonProperty("id")]
public Guid ID { get; set; }
[Required]
[JsonProperty("partKey")]
public string PartitionKey { get; set; } = string.Empty;
[JsonProperty("metaDict")]
public IDictionary<string, object> MetadataDictionary { get; set; } = new Dictionary<string, object>();
[JsonProperty("url")]
public string Url { get; set; }
} And the results would look like what CosmosClient writes: {
"metaDict": {
"@odata.etag": "\"982b588c-a06b-4f2e-b6dd-9732bdbbf143,20\"",
"Title": "A Compliance Title",
"GovernmentIDNumber": "8807",
"Salary": 123456.78,
"Location": "1600 Pennsylvania Ave NW\r\nWashington, DC 20500",
"ContentType": "Document",
"Created": "2020-05-28T17:03:48Z",
"AuthorLookupId": "1073741822",
"Modified": "2020-06-15T19:30:57Z",
"EditorLookupId": "1073741822",
"DocIcon": "png",
"FileSizeDisplay": "14622",
"ItemChildCount": "0",
"FolderChildCount": "0",
"_ComplianceFlags": "",
"_ComplianceTag": "",
"_ComplianceTagWrittenTime": "",
"_ComplianceTagUserId": "",
"_CommentCount": "",
"_LikeCount": "",
"_DisplayName": "",
"AppAuthorLookupId": "7",
"AppEditorLookupId": "7",
"Edit": "0",
"_UIVersionString": "19.0",
"ParentVersionStringLookupId": "6",
"ParentLeafNameLookupId": "6"
},
"url": "https://google.com/test.png",
"id": "dac9bcfa-1c68-498f-95bd-4f7443752a05",
"partKey": "202006",
"Discriminator": "Foo",
"_rid": "hwE9AKmqH1oBAAAAAAAAAA==",
"_self": "dbs/hwE9AA==/colls/hwE9AKmqH1o=/docs/hwE9AKmqH1oBAAAAAAAAAA==/",
"_etag": "\"00000000-0000-0000-434b-7f41007b01d6\"",
"_attachments": "attachments/",
"_ts": 1592249459
} |
Duplicate of #9914 |
Maybe I'm dense, but closing this out doesn't answer my question. Is it even possible to do this in EF Core 3.1 at all? |
@DaleyKD No, there's no way of doing this in 3.1. You can try accessing the JSON directly as a workaround https://docs.microsoft.com/en-us/ef/core/providers/cosmos/unstructured-data |
@AndriySvyryd : Thank you! That's all I needed so I didn't go insane. :) |
@AndriySvyryd - With EF Core 5.0 (or maybe even upcoming 6), is this possible yet? Currently, I can't use EF Core with Cosmos because of this limitation. I still have to use the (I'm a little embarrassed by what I currently have as my CosmosDbService because it's a nasty mix of EF Core and CosmosClient while I want to convert to full EF Core.) |
In EF Core 5 you can map them as owned shared type entity types:
|
If my |
Perfect. Thank you! |
I've been working all week trying to get EF Core 3.1 Cosmos DB provider to even somewhat work with an
IDictionary<string, object>
. So far, nothing is working ideally.Is there a way to use a Value Converter? A Backing Field? Anything like that?
This limitation is making it so that I can't use EF Core for my Cosmos project.
The text was updated successfully, but these errors were encountered: