Print Page | Close Window

UsingAGridBuilder

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1850
Printed Date: 21-Apr-2026 at 8:39pm


Topic: UsingAGridBuilder
Posted By: sky40627
Subject: UsingAGridBuilder
Date Posted: 27-May-2010 at 12:26am
I converted this application to vs 2010 and devforce 2010
 
Now i have an error wen accessing an navigational property for ex. Product.Supplier
 
{"Index was outside the bounds of the array."}
 
I have this problem with all my apps i ported to vs 2010
 
Where does this come from ?
 
StackTrace :
 
   at IdeaBlade.EntityModel.EntityQueryBuilder.<>c__DisplayClass7.<BuildMultiEqualExpr>b__6(MemberExpression expr, Int32 i)
   at System.Linq.Enumerable.<SelectIterator>d__7`2.MoveNext()
   at IdeaBlade.EntityModel.EntityQueryBuilder.And(IEnumerable`1 expressions)
   at IdeaBlade.EntityModel.EntityQueryBuilder.BuildMultiEqualExpr(IEnumerable`1 propExpressions, Object[] values)
   at IdeaBlade.EntityModel.EntityQueryBuilder.<>c__DisplayClass4.<BuildLambdaKeyQuery>b__3(EntityKey key)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at IdeaBlade.EntityModel.EntityQueryBuilder.Or(IEnumerable`1 expressions)
   at IdeaBlade.EntityModel.EntityQueryBuilder.BuildLambdaKeyQuery(IEnumerable`1 keys)
   at IdeaBlade.EntityModel.EntityQueryBuilder.BuildQuery(IEnumerable`1 keys)
   at IdeaBlade.EntityModel.EntityKeyFinder.Execute()
   at IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)
   at IdeaBlade.EntityModel.EntityManager.FirstOrNullEntity(IEntityQuery query)
   at IdeaBlade.EntityModel.ScalarEntityReference`1.QueryForEntity(EntityReferenceStrategy strategy)
   at IdeaBlade.EntityModel.ScalarEntityReference`1.GetEntity(EntityReferenceStrategy strategy)
   at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.<.ctor>b__0(NavigationEntityPropertyGetInterceptorArgs`2 args)
   at IdeaBlade.Core.PropertyInterceptor`3.HandleAction(Action`1 action, TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.<BuildTargetedCombinedAction>b__3(TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.ExecuteActions(TArgs args)
   at IdeaBlade.Core.PropertyInterceptor`3.GetValue(TInstance instance, Object context)
   at IdeaBlade.EntityModel.NavigationScalarEntityProperty`2.GetValue(TInstance instance)
   at ServerModelNorthwindIB.Employee.get_Manager() in C:\Users\Public\Documents\DevForce 2010\Learning Resources\200WNF_GridBuilder\CodeCS\ServerModelNorthwindIB\ServerModelNorthwindIB.IB.Designer.cs:line 713



Replies:
Posted By: ting
Date Posted: 27-May-2010 at 8:09pm
Hi Sky - The application you sent over is too large for us to tell what is going on.  You'll need to simplify the the solution - perhaps to just those two related objects so that we can take a look.


Posted By: sky40627
Date Posted: 12-Jul-2010 at 1:52am
this is my loaddata
private BindableList<Employee> _employees = new BindableList<Employee>();
var query = _em.BasePersons
                .Include(Employee.PathFor(sa => sa.CommissionCode))
                .Include(Employee.PathFor(sa => sa.SalesInvoiceAgents))
                .Include(Employee.PathFor(sa => sa.Address))
                .Include(Employee.PathFor(sa => sa.Address.Country))  <-- the moment i include this it fails
                 .OfType<Employee>();
_employees.ReplaceRange(query.ToList());
 
I made sure every employee had an address and each address has a country assigned to it
 
Then I create my grid and bind the data
 
GridControl employeeGridControl;
 XtraGridBindingManager bindingManager;
_GridBuilder2.CreateGrid(out employeeGridControl, out bindingManager,  _employeeBS, typeof(Employee));
 
_GridBuilder2.AddColumn(bindingManager, Employee.PathFor(e => e.Name));
_GridBuilder2.AddColumn(bindingManager, Employee.PathFor(e => e.CommissionCode.AlfaCode));
_GridBuilder2.AddColumn(bindingManager, Employee.PathFor(e => e.NumberOfUnpaidInvoices));
_GridBuilder2.AddColumn(bindingManager, Employee.PathFor(e => e.Address.City));
_GridBuilder2.AddColumn(bindingManager, Employee.PathFor(e => e.Address.Country.NameNld));
 
I had the same problem before with other data and then I could resolve the problem by adding an include in the loaddata of the extra data needed
 
 


Posted By: ting
Date Posted: 12-Jul-2010 at 7:30pm
Hi Sky,
 
We just saw a similar issue from another customer.  You can get the "Index was outside the bounds of the array" error if the foreign key references are missing from the EDMX.  I went back and looked at the solution you submitted and noticed that most of the foreign key references were not present, including the SupplierID on the Product entity.
 
Did you try to convert this from a .NET 3.5 Entity Framework model (not a good idea) or did you build it from scratch using the Entity Framework in .NET 4.0?
 


Posted By: sky40627
Date Posted: 27-Jul-2010 at 7:02am
I now made a complete new EDMX was a hell of a job, and i made some improvements.
 
Now I only seem to have the problem when the entity is inherited.
 
Employee.Commissioncode.Procent
 
where Commissioncode is inherited from a Basecode (TPH).
 
 
 



Print Page | Close Window