Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
150
Entity Framework Hieracrhy
posted

Hello,

 I have an Entity, Company, that has a property exposing a list of child entities, Car.

 For a quick run I created an instance of my Entity:

Company company = new Company() { Name = "Ford", City = "Detroit" };

and then initialized the child entity collection and added two children:

company.Car = new System.Data.Objects.DataClasses.EntityCollection<Car>();

company.Car.Add( new Car() { Name = "Mustang" } );

company.Car.Add( new Car() { Name = "Explorer" } );

I manually defined the schema with my first Band with a Key of, "Company", and the child band to a Key of, "Car".

The parent record is visible, but the child is not.  How should I be doing this?

Thank you,

Blu

Parents
No Data
Reply
  • 17259
    Offline posted

    If you don't see the "+" sign beside each row, yu need to write:

    grid.DisplayLayout.ViewStyle = ViewStyle.MultiBand

    I think you also shouldn't always construct a new collection for Car. When you make a new Company you can start adding Cars without constructing its collection first. If you want to make sure there is nothing in the collection then use Clear(). This is very important when you bind the collection. If you construct a new collection you might lose the binding.

Children