Dealing with collection type in MongoDb provider efcore
I recently tried out the new provider for EF Core (MongoDb)
The model I got
When I insert the programming language with the versions list mongodb add the new document just fine
But when I try to retrieve data from the database
there's an exception below
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