[EF-64] The include method throws an exception Created: 13/Oct/23  Updated: 27/Oct/23  Resolved: 20/Oct/23

Status: Closed
Project: Entity Framework
Component/s: None
Affects Version/s: Public Preview 1
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Maghawry Hussein Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

My project is a Todo Demo.

I have 2 classes Todo and Category with relations 1 to Many

When I try to get Todos with category it throws an exception 

// The Line which thows.
var result = await _context.Todos.Include(x=>x.Category).ToListAsync(); 
 
 
 
public class Category
{
    public ObjectId _id { get; set; }
    public string Name { get; set; }
    public ICollection<Todo> Todos { get; set; }
}
 
public class Todo
{
    public ObjectId _id { get; set; }
    public string Name { get; set; } = null!;
    public string Description { get; set; } = null!;
    public bool IsDone { get; set; }
    public ObjectId CategoryId { get; set; }
    public Category Category { get; set; }
}
 
public class TodoDbContext:DbContext
{
    public DbSet<Todo> Todos { get; init; } = null!;
    public DbSet<Category> Categories { get; init; } = null!;
    
    
    public TodoDbContext(DbContextOptions<TodoDbContext> options):base(options)
    {
        
    }
 
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<Todo>()
            .HasOne(t => t.Category)
            .WithMany(c => c.Todos)
            .HasForeignKey(t => t.CategoryId)
            .IsRequired();
 
        modelBuilder.Entity<Category>()
            .HasMany(c => c.Todos)
            .WithOne(t => t.Category);
 
    }
}
 
builder.Services.AddDbContext<TodoDbContext>(opt =>
{
    var database = new MongoClient(builder.Configuration.GetConnectionString("Default")).GetDatabase("Todos");
    opt.UseMongoDB(database.Client, database.DatabaseNamespace.DatabaseName);
});



 Comments   
Comment by James Kovacs [ 20/Oct/23 ]

Closed as Works as Designed as we do not support Include, but may support it in a future version.

Comment by James Kovacs [ 20/Oct/23 ]

Hi, maghawry.hussein20@gmail.com,

Thank you for trying out Public Preview 1 of our EF Core Provider for MongoDB. Public Preview 1 does not implement support for Include AKA joins as noted in the Limitations & Roadmap. Rather than using Include, you can simply nest owned entities inside a root document and those owned entities will appear as sub-documents in the database. Depending on user feedback, we may decide to add Include support in a future version.

Sincerely,
James

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