Problems with databinding after upgrading

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 09-Sep-2006 13:32:49   

Hi,

I use Janus grids and with the old 1.2005 generated code, I was able to bid this to a grid by passing the EntityCollection directly to the DataSource property of the grid.

I use teh following code in my grid control to set the datasource

private IBindingList mobjGridSource;

        public IBindingList CTLDataSource
        {
            get {return mobjGridSource;}
            set
            {
                mobjGridSource= value;
                this.DataSource=mobjGridSource;
                CTLRefetch();
            }
        }

Then all I did was pass the EntityCollection to the control


EntityCollection mGridSource;
this.grdItems.CTLDataSource=mGridSource;

This worked perfrctly under v1.2005 code and was just what I wanted because it did not matter what the entitycollection was a collection of.

In V2.0 code , I found that I got complie errors saying the EntityCollection can not be converted to IBindingList so I changed the code to


EntityCollection mGridSource;
this.grdItems.CTLDataSource=(IBindingList) mGridSource;

which made it compile perfectly, howere when I run the application my grids are empty!!

How do I get my grids back using V2.0 code?

Many thanks, I am sure there is a simple solution, but not being an expert I am unable to work out what

Reagrds

Huw

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 09-Sep-2006 23:52:53   

hplloyd wrote:

In V2.0 code , I found that I got complie errors saying the EntityCollection can not be converted to IBindingList so I changed the code to


EntityCollection mGridSource;
this.grdItems.CTLDataSource=(IBindingList) mGridSource;

which made it compile perfectly, howere when I run the application my grids are empty!!

How do I get my grids back using V2.0 code?

Is this your actual code above? If so, you never instantiate the mGridSource collection. Could this be the issue?

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 10-Sep-2006 10:59:45   

Sorry I left out the code for instatiating the collection, the code I show is just the generic code for the user control I use.

I would obviously populate the collection first and then pass the populated collection to the user control.

Do you have a bit of sample code that would show how you think I can use an EntityCollection to populate a grid under v2.0..... has the code changed from v1.2005?

Many thanks

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 10-Sep-2006 18:43:42   

hplloyd wrote:

Sorry I left out the code for instatiating the collection, the code I show is just the generic code for the user control I use.

Got it. Thanks for clarifying.

hplloyd wrote:

Do you have a bit of sample code that would show how you think I can use an EntityCollection to populate a grid under v2.0..... has the code changed from v1.2005?

It depends on which template you're using: Self-Servicing or Adapter. Have a look at the documentation section called "Using the generated code...Using the entity collection classes" for adapter template (which it appears you are using). If you're targeting .NET 2.0 and adapter it would look something like this:


        EntityCollection<ProductEntity> col = new EntityCollection<ProductEntity>();
        DataAccessAdapter daa = new DataAccessAdapter();
        daa.FetchEntityCollection(col, null);
        this.theGrid.DataSource = col;
        this.theGrid.DataBind();

This is an ASP.NET example, but you get the idea. There are other ways besides this one by the way. Hope this helps though.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 15:49:30   

Hi,

I've got two remarks:

LLBLGen 2 now uses generics with entitycollection. There is still a non generic version of entitycollection, called EntityCollectionNonGeneric, and which EntityCollection inherits from (when not used with explicit generics syntax). So if you do a standard port, your EntityCollections get transformed into EntityCollectionNonGeneric unless you update them with their generics implementation.

As for the capabilities, EntityCollectionNonGeneric does have pretty much the same capabilities as EntityCollection(Of TEntity As {EntityBase2, IEntity2}) so your problem does not come from there.

Now EntityCollection does not implement IBindingList, which is why your casting does not produce much. However it implements IListSource so you should still be able to bind.

Now if you want to keep with IBindingList, you should look for EntityView2<TEntity> which does implement that interface.

Have a look in the user manual at "Generated code - Using the EntityView2 class, Adapter" It does not introduc much overhead since your entitycollections (generic or not) can provide the corresponding EntityView in a single line of code.

Cheers

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 11-Sep-2006 16:11:29   

Many thanks

Changing my code to use IListSource rather than I BindingList should do the trick for now.

I think I will leave the migration to the use of generics for another day wink !!!

Regards

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 17:01:04   

Well actually, I think I would have gone for changing your mGridSource into EntityViews since you get more control with your entityviews than with your collections, and I don't think it costs you much to make that change since you can keep up with your IBindingList.

No big deal for a straight migration anyway.

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 11-Sep-2006 22:17:52   

Thanks I will look into it