[EF-91] What is wrong with this model Created: 17/Jan/24  Updated: 24/Jan/24

Status: Waiting for Reporter
Project: Entity Framework
Component/s: None
Affects Version/s: Public Preview 1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Юрий Романов Assignee: Damien Guard
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello, i'm using EF in my F#\C# project.

The model is simple:

 

[<CLIMutable>]
type EditorData = {
    text:string
}
 
[<CLIMutable>]
type EditorBlock = {
    id:string
    ``type``:string
    data: EditorData
}
 
[<CLIMutable>]
type News = {
    [<BsonId>]
    [<BsonRepresentation(BsonType.Int32)>]
    Id:int
    Category:int
    User:int
    Title:string
    Slug:string
    Added:DateTime
    JsonContent:ResizeArray<EditorBlock>
} 

i've saved my data and MongoDB Compass shows this:

 

 

{
  "_id": 1,
  "Added": {
    "$date": "2024-01-17T14:21:55.412Z"
  },
  "Category": 1,
  "Slug": "-",
  "Title": "Test News",
  "User": 1,
  "JsonContent": [
    {
      "id": "1FBsOgCe3H",
      "type": "paragraph",
      "data": {
        "text": "тестовый параграф"
      }
    },
    {
      "id": "ZNptxV9d72",
      "type": "paragraph",
      "data": {
        "text": "ещё один"
      }
    },
    {
      "id": "k_UNq6WE53",
      "type": "paragraph",
      "data": {
        "text": "third"
      }
    }
  ]
} 

if i try just to find record:

 

 

InvalidOperationException: The LINQ expression 'o' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information. 

but if i remove data: EditorData from EditorBlock everything works

 

thank you for any help



 Comments   
Comment by Damien Guard [ 24/Jan/24 ]

The reason I asked about the Bson attributes is we are considering adding a Convention provider for our EF driver that would detect them and apply the equivalent EF metadata as necessary but we're trying to get some data points about expectations.

I'll mark the issue as a duplicate at this end which will close it.

Comment by Юрий Романов [ 24/Jan/24 ]

damien.guard@mongodb.com hello, thanks for the feedback. Do i need to close the issue?

I always use my keys and generate them manually in any database provider, strange but everything works with

BsonId and BsonRepresentation ... or maybe EF just handles my generation well.

Comment by Damien Guard [ 23/Jan/24 ]

Hello.

Unfortunately objects (documents) with more than one level of nesting do not work in preview release 1. This is what the error message is from.

The fix for this has gone into the main branch but it will be some time before we ship another update with the fix in it.

Additionally BsonId and BsonRepresentation etc. are not recognized by the EF metadata system. Out of curiosity did you try to use them because the documentation made you think they would be honored by the MongoDB EF Core Provider or did you have familiarity with the existing MongoDB C# Driver and decided to try them out?

Thanks

Damien

Comment by Юрий Романов [ 18/Jan/24 ]

works with [BsonIgnoreExtraElements] and classic MongoDB.Driver.Core 

but fails anyway with EF

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