Представьте следующую ситуацию: у меня есть два класса в отношениях один-ко-многим, и я пытаюсь загрузить все объекты из одного класса и одновременно загрузить все связанные объекты. Вот скелетная структура для обоих этих классов:DataContext с DataLoadOptions и LoadWith возвращает неправильное количество записей
public class Parent
{
//... id and other members omitted
[Association(Name = "FK_Parent_Children", Storage = "_entries", ThisKey = "Id")]
public EntitySet<Child> Children {
get { return _children; }
}
private readonly EntitySet<Child> _children = new EntitySet<Child>();
}
public class Child
{
//... id and other members omitted
[Column]
internal int? _belongId;
private EntityRef<Parent> _belong;
[Association(Name = "FK_Parent_Children", Storage = "_belong", ThisKey = "_belongId", OtherKey = "Id", IsForeignKey = true)]
public Parent Belong
{
get { return _belong.Entity; }
set { _belong.Entity = value; }
}
}
И тут приходит код, который я пытался для загрузки всех объектов:
using(var context = new MyContext())
{
context.DeferredLoadingEnabled = false;
var options = new DataLoadOptions();
options.AssociateWith<Parent>(c => c.Children.OrderByDescending(x => x.Born).Take(100));
options.LoadWith<Parent>(m => m.Children);
context.LoadOptions = options;
var parents = context.Parents.OrderBy(m => m.LastName).ToList();
return parents;
}
Интересно максимум ровно один «ребенок» загружается в EntitySet все время, хотя часто есть больше объектов, связанных с одним «родителем». Любая идея, что я могу делать неправильно здесь?