Dealing with collection type in MongoDb provider efcore

I recently tried out the new provider for EF Core (MongoDb) The model I got
[Collection("ProgrammingLanguages")]
public class ProgrammingLanguage : BaseEntity
{
public string Name { get; set; } = string.Empty;
public string Logo { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string? URL { get; set; }
public DateTime ReleaseDate { get; set; }

public ICollection<ProgrammingLanguageVersion>? Versions { get; set; }
}
[Collection("ProgrammingLanguages")]
public class ProgrammingLanguage : BaseEntity
{
public string Name { get; set; } = string.Empty;
public string Logo { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string? URL { get; set; }
public DateTime ReleaseDate { get; set; }

public ICollection<ProgrammingLanguageVersion>? Versions { get; set; }
}
public class ProgrammingLanguageVersion
{
public string? URL { get; set; }
public DateTime ReleaseDate { get; set; }
}
public class ProgrammingLanguageVersion
{
public string? URL { get; set; }
public DateTime ReleaseDate { get; set; }
}
When I insert the programming language with the versions list mongodb add the new document just fine
//Insert code

context.ProgrammingLanguages.Add(new ProgrammingLanguage()
{
Name = "Test Programming Lang 2",
Versions = new List<ProgrammingLanguageVersion>()
{
new()
{
ReleaseDate = DateTime.Now,
URL = "bruh"
}
}
});

context.ChangeTracker.DetectChanges();
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
await context.SaveChangesAsync();
//Insert code

context.ProgrammingLanguages.Add(new ProgrammingLanguage()
{
Name = "Test Programming Lang 2",
Versions = new List<ProgrammingLanguageVersion>()
{
new()
{
ReleaseDate = DateTime.Now,
URL = "bruh"
}
}
});

context.ChangeTracker.DetectChanges();
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
await context.SaveChangesAsync();
But when I try to retrieve data from the database
var result = context.ProgrammingLanguages;
var result = context.ProgrammingLanguages;
there's an exception below
2 Replies
TotechsStrypper
TotechsStrypperOP7mo ago
Exception
System.InvalidOperationException: Type of ExtraElements member must be BsonDocument or implement IDictionary<string, object>.
at MongoDB.Bson.Serialization.BsonClassMap.SetExtraElementsMember(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Attributes.BsonExtraElementsAttribute.Apply(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Conventions.AttributeConventionPack.AttributeConvention.Apply(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Conventions.ConventionRunner.Apply(BsonClassMap classMap)
at MongoDB.Bson.Serialization.BsonClassMap.AutoMapClass()
at MongoDB.Bson.Serialization.BsonClassMap.AutoMap()
at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
System.InvalidOperationException: Type of ExtraElements member must be BsonDocument or implement IDictionary<string, object>.
at MongoDB.Bson.Serialization.BsonClassMap.SetExtraElementsMember(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Attributes.BsonExtraElementsAttribute.Apply(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Conventions.AttributeConventionPack.AttributeConvention.Apply(BsonMemberMap memberMap)
at MongoDB.Bson.Serialization.Conventions.ConventionRunner.Apply(BsonClassMap classMap)
at MongoDB.Bson.Serialization.BsonClassMap.AutoMapClass()
at MongoDB.Bson.Serialization.BsonClassMap.AutoMap()
at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
Omnissiah
Omnissiah7mo ago
i guess you have to show BaseEntity
Want results from more Discord servers?
Add your server