Hello,
I’ve got two collections, documents in one collection have an array of id’s that reference docs in another collection similar to what is described here (except a lookup by _id).
db.classes.insertMany( [
{ _id: 1, title: "Reading is ...", enrollmentlist: [ 6, 5, 1 ], days: ["M", "W", "F"] },
{ _id: 2, title: "But Writing ...", enrollmentlist: [2, 1 ], days: ["T", "F"] }
] )
db.members.insertMany( [
{ _id: 1, name: "artie", joined: new Date("2016-05-01"), status: "A" },
{ _id: 2, name: "giraffe", joined: new Date("2017-05-01"), status: "D" },
{ _id: 3, name: "giraffe1", joined: new Date("2017-10-01"), status: "A" },
{ _id: 4, name: "panda", joined: new Date("2018-10-11"), status: "A" },
{ _id: 5, name: "pandabear", joined: new Date("2018-12-01"), status: "A" },
{ _id: 6, name: "giraffe2", joined: new Date("2018-12-01"), status: "D" }
] )
db.classes.aggregate( [
{
$lookup:
{
from: "members",
localField: "enrollmentlist",
foreignField: "_id",
as: "enrollee_info"
}
}
] )
I’ve been trying to model this in EF Core as follows but have not been able to get it working no matter how I configure the relationship:
public class Classes
{
public int Id { get; set; }
...
public virtual List<Member> EnrolleeInfo { get; set; } = new List<Member>();
}
public class Member
{
public int Id { get; set; }
...
}
The readme mentions that the EF Core provider supports the following:
Foreign keys and navigation traversal via EF.Proxy
But not sure if that includes the scenario above. Been searching high and low on the interwebs and digging through the tests in the EF Core provider and haven’t turned anything up. Any idea how this can be done?
Thx!