Hi,
I've made a small example with a "Person" class, which contains a list of Pets. In addition, there'se a simple repository that can save / delete / select Person objects. Now I put a form view (or details view) on my form, choose an object data source which points to my repository. So far it works perfectly, I can create, update, delete people... I can even show my collection of pets in an item template in my view.
But when I am updating a person, my collection of pets is cleared! When I look at the "Updating" event of the object binding source, e.InputParameters contains all my values that I have entered, but the pets collection always contains 0 items. When I look at the Selected event of the object binding source, my e.ReturnValue contains my selected person including pets, which is correct. Any ideas?
Here is my person class and my repository. This is a small sample of what is actually a linq2hibernate project.
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public List<Pet> Pets { get; set; }
public Person()
{
Pets = new List<Pet>();
}
}
[DataObject]
public class Repository
{
List<Person> people = new List<Person>();
public Repository()
{
//Code to load the person list
}
public Person FindByID(int ID)
{
return people.SingleOrDefault(x => x.ID == ID);
}
public List<Person> FindAll()
{
return people;
}
public void Save(Person person)
{
// code to save a person
// Here you can see a person's pets collection is always empty
// when this method is called by the objectdatasource
}
public void Delete(Person person)
{
}
public void Insert(Person person)
{
}
}