I have an M to N relationship on my Database. I took the sample Database "sakila" from the MySql page. I have set up my Model Objects as follows.
Film Table
public partial class Film
{
public Film()
{
FilmActor = new HashSet<FilmActor>();
FilmCategory = new HashSet<FilmCategory>();
Inventory = new HashSet<Inventory>();
}
//Some Properties
public ICollection<Inventory> Inventory { get; set; }
}
Linking Table Inventory
public partial class Inventory
{
public Inventory()
{
Rental = new HashSet<Rental>();
}
public int InventoryId { get; set; }
public short FilmId { get; set; }
public byte StoreId { get; set; }
public DateTimeOffset LastUpdate { get; set; }
public Film Film { get; set; }
public Store Store { get; set; }
public ICollection<Rental> Rental { get; set; }
}
Store Table
public partial class Store
{
public Store()
{
Customer = new HashSet<Customer>();
Inventory = new HashSet<Inventory>();
Staff = new HashSet<Staff>();
}
//More Properties
public ICollection<Inventory> Inventory { get; set; }
}
When I go to retrieve the Data through a Repository I get back a list of Store objects that has a list of Inventory that has a list of films that has a list of stores...
In other words: store[2]->inventory[2270]->film->store[2]->inventory... ad infinitum.
So how do I make this stop when my Model gets to the film objects?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…