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
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.
I commented out: company.Car = new System.Data.Objects.DataClasses.EntityCollection<Car>();
I changed the view style in Grid_InitializeLayout and it did not add the + symbol for the child rows.
private void Grid_InitializeLayout( ...
{
...
e.Layout.ViewStyle = ViewStyle.MultiBand;
}
Setting the ViewStyle on the grid is unlikely to help, since MultiBand is the default. So this would only be a problem if you had already set this property to SingleBand.
What exactly is System.Data.Objects.DataClasses.EntityCollection? I couldn't find this type.I assume it implements IList<> or IBindingList<>, so that should be okay.
What is the grid's DataSource in this scenaria? Is is a single Company? Or a list of companies?
What does the Car property return before you set it to a new EntityCollection? Is it returning an empty list or is it null?
Are you binding the grid before or after adding the Cars?
The entity collection column type was set by the designer when I populated the edmx from the database.
Here is the class declaration from looking at the assembly with Reflector:
public sealed class EntityCollection<TEntity> : RelatedEnd, ICollection<TEntity>, IEnumerable<TEntity>, IEnumerable, IListSource where TEntity: class, IEntityWithRelationships
The grid's datasource is a List<Company> with more then one company. Each company has Car instances added to the Car property.
I did not need to instantiate the Car property with a new List, it has an empty List to begin with.
I add the Companies and their Cars prior to binding the Grid, I use: this.ResultsGrid.DataSource = companies;
It appears to me that the EntityCollection doesn't support any of the required interfaces that would mark it as a child list by the DotNet BindingManager.
In order for this to work, the list of cars must implement IList or IBindingList.
It does implement IListSource, which is interesting. This seems to imply that the EntityCollection contains multiple lists. This makes it unsuitable to display as a set of child bands, but theoretically, you could bind the grid directly to the Cars collection, then, as long as you specified a DataMember as well as a DataSource.
From MSDN:
"An EntityCollection<(Of <(TEntity>)>) is a collection of objects of a particular entity type that represents the "many" end of a one-to-many or many-to-many relationship."
I tried to set the data memeber to "Cars", but a binding exceptions was thrown.
Is there a quick example of binding the UltraWinGrid to entities from the EntityFramework, I only see dataset based examples in the, "Dig into Code" section? I can start there and see if the Grid will work for our applications.
Thanks for the reply.
I'm afraid I know of no samples using the EntityFramework. I'm not really familiar with this framework. But from what you have posted here, it does not appear to be designed for data binding - at least not in a hierarchical situation.
Hi,
There aren't any samples of this that I know of.
I'm afraid I don't know of any plans to create some. I recommend that you Submit a feature request to Infragistics.
Hi Mike, It appears the last mention of entity framework and infragistics was almost 2 years ago. Has there been any samples released regarding the binding of EF4 and infragistics controls, are there any plans to do so?