At first, I needed to define a "many-to-many" self referencing in EF Code First. Unfortunately this is not supported by Breeze. I mean whenever I query breeze, I don't get no data for my expand on Friends
. See here: Self-referencing many-to-many relationship EF code first
So the solution seems to be a "many-to-one-to-many".
So here is my classes:
public class Person
{
public int Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public virtual List<LinkedPerson> Friends { get; set; }
}
public class LinkedPerson
{
[Key, Column(Order = 0)]
public int PersonId { get; set; }
[Key, Column(Order = 1)]
public int PersonRelatedId { get; set; }
public virtual Person Person { get; set; }
public virtual Person PersonRelated { get; set; }
}
With the following EF Fluent API:
modelBuilder.Entity<LinkedPerson>()
.HasRequired(p => p.Person)
.WithMany()
.WillCascadeOnDelete(false);
At runtime, the database is generated successfully but I am still unable to query breeze to retrieve the Friends property. As a result, I get all data in my query except the Friends property.
Does someone have an idea how to achieve this?
Thanks.