namespace Entities.Models
{
[BsonIgnoreExtraElements]
public class UPModel
{
[JsonProperty(PropertyName = "_id")]
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string BsonId { get; set; } = string.Empty;
[BsonElement("resource")]
public Resource Resource{ get; set; }
[BsonElement("preference")]
public Preference Preference { get; set; }
}
[BsonIgnoreExtraElements]
public class Resource
{
[BsonElement("id")]
public string Id { get; set; }
[BsonElement("identifiers")]
public dynamic Identifiers { get; set; }
}
[BsonIgnoreExtraElements]
public class Preference
{
[BsonElement("id")]
public string Id { get; set; }
[BsonElement("value")]
public dynamic Value { get; set; }
}
}
< /code>
Dokument, das für dieses Modell im DB erstellt werden muss: < /p>
{
"id":"uniqueIdentifier",
"preference": {
"id": "dummyPreferenceId",
"value": {
"favorites": [
"dummyFavorites1"
]
}
},
"resource": {
"identifiers": {
"userId": 99,
"routeUrl": "dummyRouteURL",
"type": "standard"
},
"id": "dummyResourceId"
}
}
< /code>
Ausnahme: < /p>
MongoDB.Bson.BsonSerializationException
HResult=0x80131500
Message=An error occurred while serializing the Resource property of class UPModel: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Source=MongoDB.Bson
StackTrace: "Removed for Readability"
Inner Exception 1:
BsonSerializationException: An error occurred while serializing the Resource property of class UPModel: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Inner Exception 2:
BsonSerializationException: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Inner Exception 3:
BsonSerializationException: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Ich suche nach einer Möglichkeit, den dynamischen Objekttyp C# in MongoDB
Ich versuche, meine Datenbank von Kosmos nach Mongo zu migrieren. />[code]_collection.InsertOneAsync(document);[/code] Modell: [code]namespace Entities.Models { [BsonIgnoreExtraElements] public class UPModel { [JsonProperty(PropertyName = "_id")] [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string BsonId { get; set; } = string.Empty;
[BsonElement("resource")] public Resource Resource{ get; set; }
[BsonElement("preference")] public Preference Preference { get; set; } }
[BsonIgnoreExtraElements] public class Resource { [BsonElement("id")] public string Id { get; set; }
[BsonElement("identifiers")] public dynamic Identifiers { get; set; } }
[BsonIgnoreExtraElements] public class Preference { [BsonElement("id")] public string Id { get; set; }
[BsonElement("value")] public dynamic Value { get; set; } } } < /code> Dokument, das für dieses Modell im DB erstellt werden muss: < /p> { "id":"uniqueIdentifier", "preference": { "id": "dummyPreferenceId", "value": { "favorites": [ "dummyFavorites1" ] } }, "resource": { "identifiers": { "userId": 99, "routeUrl": "dummyRouteURL", "type": "standard" }, "id": "dummyResourceId" } } < /code> Ausnahme: < /p> MongoDB.Bson.BsonSerializationException HResult=0x80131500 Message=An error occurred while serializing the Resource property of class UPModel: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer. Source=MongoDB.Bson StackTrace: "Removed for Readability" Inner Exception 1: BsonSerializationException: An error occurred while serializing the Resource property of class UPModel: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Inner Exception 2: BsonSerializationException: An error occurred while serializing the Identifiers property of class Resource: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.
Inner Exception 3: BsonSerializationException: Type Newtonsoft.Json.Linq.JObject is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer. [/code] Ich suche nach einer Möglichkeit, den dynamischen Objekttyp C# in MongoDB
Ich habe eine Laravel 5.3-App und ein Update-Formular, über das ich Benutzerprofilwerte sende. Eines davon ist auch das Benutzerbild. Ich erstelle ein verstecktes Eingabefeld dafür. Wenn der Benutzer...
Ich arbeite mit .NET 6 und MongoDB und habe ein Modell, das eine dynamische Metadateneigenschaft enthält, die als Objekt gespeichert ist. Das Lesen dieses Objekts von MongoDB funktioniert perfekt,...