Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Problem with e.ContainedCollection.AddRange()
 

Pages: 1
LLBLGen Pro Runtime Framework
Problem with e.ContainedCollection.AddRange()
Page:1/1 

  Print all messages in this thread  
Poster Message
Meteor
User



Location:
Australia
Joined on:
06-Apr-2007 09:44:09
Posted:
67 posts
# Posted on: 19-Oct-2007 04:09:04.  
I have LLBLGen Pro 2.5 using adapter with SqlServer 2k and Asp.Net 2.0

I have two GridViews, both of which are bound to separate LLBLGenProDataSource2 controls. The datasource controls should contain different views of
Code:
EntityCollection<OptionContractEntity>


A button click event retrieves the data into the Session, then creates two separate
Code:
EntityView2<OptionContractEntity>
Session objects and calls the '.Select()' method of the datasource controls.

I've handled the PerformSelect event on each of the datasource controls and I'm trying to use
Code:
e.ContainedCollection.AddRange()
to add the two EntityViews to the datasource controls. I've called the two Views 'Calls' and 'Puts', and I'm using
Code:
e.ContainedCollection.AddRange(Calls.ToEntityCollection())
but getting the error 'c isn't of the right type'.

.AddRange() obviously doesn't like the parameter I'm passing to it, even though the objects contained in the parameter implement the IEntity2 interface - as specified in the intellisense.

What am I doing wrong? I've also tried:

Code:
IEntityCollection2 col = Puts.ToEntityCollection();
e.ContainedCollection.AddRange(col);


and still get the error.

Is there another way to do this?

All I want to do is retrieve all the data in one hit, and assign the appropriate filtered views to each of the datasource controls.
Visual Studio 2008 sp1, SelfServicing/Adapter, C#, .Net 3.5 sp1, Sqlserver 2008 Express  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14473 posts
# Posted on: 19-Oct-2007 12:06:55.  
Is the DataSource's EntityFactoryTypeName declared to be set to OptionContractEntityFactoy?
Would you please post the ASPX declaration of both datasources?


  Top
Meteor
User



Location:
Australia
Joined on:
06-Apr-2007 09:44:09
Posted:
67 posts
# Posted on: 20-Oct-2007 01:19:06.  
Yes, it is set to be of type OptionContractEntityFactory.

Sorry, I can't post the code because I'm on holidays as from last night Wink , but it's a general type of question, isn't it?
Visual Studio 2008 sp1, SelfServicing/Adapter, C#, .Net 3.5 sp1, Sqlserver 2008 Express  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37409 posts
# Posted on: 21-Oct-2007 11:37:43.  
- Fetch collection (1st collection)
- create the view for the other collection you want to create on the fetched collection
- call the ToEntityCollection method on that view (becomes 2nd collection)
- assign first collection to datasourcecontrol A and the second collection to datasourcecontrol B.

You'll have the same entity instances in both collections. Datasourcecontrols aren't controllers, so they don't offer you to bind views of data OUTSIDE the datasource controls. that's not how the design of datasource controls works (not my design, MS cooked that up). So datasource controls manage the data inside themselves.

Therefore, it might be that an entity which is in both collections gets altered twice, but that's unavoidable due to the design of the datasource controls.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Meteor
User



Location:
Australia
Joined on:
06-Apr-2007 09:44:09
Posted:
67 posts
# Posted on: 22-Oct-2007 01:43:41.  
Thanks Otis. The grids are read-only anyway, so it doesn't matter about editing. I'll try what you've suggested.
Visual Studio 2008 sp1, SelfServicing/Adapter, C#, .Net 3.5 sp1, Sqlserver 2008 Express  Top
Meteor
User



Location:
Australia
Joined on:
06-Apr-2007 09:44:09
Posted:
67 posts
# Posted on: 23-Oct-2007 01:05:00.  
Right, tried again.

The problem is, how to assign the two collections to the datasource controls?

In PerformSelect, e.ContainedCollection is read-only, and outside PerformSelect, LLBLGenProDataSource1.EntityCollection is read-only.

It seems the only way is to supply a filter to adapter.GetMulti() inside PerformSelect using e.ContainedCollection as one of the parameters.

I can't see how to assign a collection to the datasource.


Visual Studio 2008 sp1, SelfServicing/Adapter, C#, .Net 3.5 sp1, Sqlserver 2008 Express  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14473 posts
# Posted on: 23-Oct-2007 12:10:24.  
Quote:
In PerformSelect, e.ContainedCollection is read-only

I don't think it's readonly, you can fetch it, i.e add entities to it.
Therefore it's not readOnly.
Quote:
It seems the only way is to supply a filter to adapter.GetMulti() inside PerformSelect using e.ContainedCollection as one of the parameters.

I think you mean adapter.FetchEntityCollection();

Please post a simple Repro solution. This will enable us to reproduce the issue as quick as possible.

Also the complete exception text and stack trace please.
  Top
tprohas
User



Location:
Tucson, AZ
Joined on:
23-Mar-2004 00:00:43
Posted:
257 posts
# Posted on: 09-Jul-2008 21:07:58.  
Hello all,

I'm now having this same exact problem. The following is the code that I'm using and I receive the same error. Can someone please help?

Code:

void requestItemsDS_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
{
    EntityCollection<RequestOrderItemEntity> orderItems = new EntityCollection<RequestOrderItemEntity>();
    SD.LLBLGen.Pro.ORMSupportClasses.EntityView2<RequestOrderItemEntity> view = orderItems.DefaultView;
    e.ContainedCollection.AddRange(view.ToEntityCollection());
}


Or

Code:

void addNewItem_Click(object sender, EventArgs e)
{
    EntityCollection<RequestOrderItemEntity> orderItems = new EntityCollection<RequestOrderItemEntity>();
    SD.LLBLGen.Pro.ORMSupportClasses.EntityView2<RequestOrderItemEntity> view = orderItems.DefaultView;

    // How do we add this to the grid.
    this.requestItemsDS.EntityCollection.AddRange(view.ToEntityCollection());
}


Both produce the following error.

Quote:

c isn't of the right type


Aaron Prohaska
http://www.verdesoft.com/
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37409 posts
# Posted on: 10-Jul-2008 10:47:54.  
The problem is caused by the fact that the datasourcecontrol internally creates an EntityCollectionNonGeneric(), which is an EntityCollectionBase2<EntityBase2>. This means that it implements ICollection<EntityBase2> and ICollection<SomeEntityType> isn't castable to ICollection<EntityBase2> because that would require covariance which isn't supported in C# nor VB.NET

AddRange simply loops over the collection passed in and calls Add(), so there are two workarounds for this:
1) use an EntityCollectionNonGeneric and pass that to the AddRange() method in this situation
or
2) loop yourself over the entityview and add the entities using Add().

Adding an AddRange() overload which fixes this is tempting, but it could break VB.NET compilers as that compiler easily gets confused with multiple matching overloads.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.