ICollection<Entity> from EntityView2<Entity>

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 29-Oct-2007 19:12:01   

Background: I'm using the castle project's monorail for a website and using the latest release of LlblGenProv2.5 rather than active record/NHiberate.

They have a component that provides a paginated grid. I need to provide an ICollection<> to the constructor.

EntityCollection2<> provides ICollection<>, but as far as I can tell EntityView2<> doesn't.

Questions: Is there a better way to get an ICollection<> from EntityView2<> than using the ToEntityCollection() method?

Are ther plans to have EntityView2<> provide ICollection?

If I do use ToEntityCollection() method, I see there is an override that specifies a starting position ToEntityCollection(i), but not one that lets me only copy j items i.e. ToEntityCollection(i,j). Could this be added?

For NonGeneric collections there are some overrides that want IList but again I haven't found a good way to get an IList from IEntityView2.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2007 03:30:16   

As far as I know, _EntityView2 _implements _IBindingList _that implements _IList _and ICollection.

So, the next lines are valid:

EntityView2<CustomerEntity> customersView = new EntityView2<CustomerEntity>(customers);

IList myList = customersView;
ICollection myCollection = customersView;

So binding to a EntityView2 directly should works.

David Elizondo | LLBLGen Support Team
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 30-Oct-2007 13:31:29   

As far as I know, EntityView2 implements IBindingList that implements IList and ICollection.

That's what I thought too.

So binding to a EntityView2 directly should works.

I'm not binding, I'm feeding my data into a method that wants


PaginationHelper.CreatePagination<T>(Controller controller, ICollection<T> datasource, int pagesize);                       

or


PaginationHelper.CreatePagination(Controller controller, IList datasource, int pagesize);                       

When I use an EntityCollection2<T> it is happy, when I use an EntityView2<T> it is not rage

for example


EntityView2<YyyyMmInvoice01Entity> evReportData =  (EntityView2<YyyyMmInvoice01Entity>)invoiceStatus02Collection.CreateView(filterInvoice);
                
PropertyBag["items"] = PaginationHelper.CreatePagination<YyyyMmInvoice01Entity>(this, evReportData, 20);

Gives an error at compile time and


EntityView2<YyyyMmInvoice01Entity> evReportData =  (EntityView2<YyyyMmInvoice01Entity>)invoiceStatus02Collection.CreateView(filterInvoice);
                
PropertyBag["items"] = PaginationHelper.CreatePagination<YyyyMmInvoice01Entity>(this, (ICollection<YyyyMmInvoice01Entity>)evReportData, 20);

Gives a cast error at run time. But


EntityView2<YyyyMmInvoice01Entity> evReportData =  (EntityView2<YyyyMmInvoice01Entity>)invoiceStatus02Collection.CreateView(filterInvoice);
                
PropertyBag["items"] = PaginationHelper.CreatePagination<YyyyMmInvoice01Entity>(this, evReportData.ToEntityCollection(), 20);

does work?? So what am I doing wrong with EntityView2<T>.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 30-Oct-2007 18:38:04   

arschr wrote:

As far as I know, EntityView2 implements IBindingList that implements IList and ICollection.

That's what I thought too.

Though ICollection<T> isn't the same as ICollection.

ICollection is a pretty meaningless interface anyway. That's why the view also implements IEnumerable<T>.

I'm not binding, I'm feeding my data into a method that wants


PaginationHelper.CreatePagination<T>(Controller controller, ICollection<T> datasource, int pagesize);                       

or


PaginationHelper.CreatePagination(Controller controller, IList datasource, int pagesize);                       

When I use an EntityCollection2<T> it is happy, when I use an EntityView2<T> it is not rage

Why haven't they implemented it with IEnumerable<T> or IList...

Anyway, if you want to use this, you indeed need to convert the view to a collection at the moment.

We could add IList<T> in the future, if that satisfies 3rd party libraries more. Microsoft has moved their framework code to IEnumerable<T> everywhere, so I think it's a matter of time before the rest of the frameworks follows that approach (we don't use it as much yet either)

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 30-Oct-2007 19:36:32   

Why haven't they implemented it with IEnumerable<T> or IList...

Don't know about IEnumerable<T>. They do support IList (nongeneric), but that doesn't seem to work with LLBLGen's IEntityView2.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 31-Oct-2007 10:34:00   

arschr wrote:

Why haven't they implemented it with IEnumerable<T> or IList...

Don't know about IEnumerable<T>. They do support IList (nongeneric), but that doesn't seem to work with LLBLGen's IEntityView2.

It should, it doesn implement IList (non-generic version)

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 31-Oct-2007 11:31:18   

It should, it doesn implement IList (non-generic version)

I don't understand what you are saying in this sentence. This Monorail method will except an IList but not an IList<T>. You seem to be saying it should work, but that IEntityView2 doesn't implement IList?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 31-Oct-2007 11:45:49   

arschr wrote:

It should, it doesn implement IList (non-generic version)

I don't understand what you are saying in this sentence. This Monorail method will except an IList but not an IList<T>. You seem to be saying it should work, but that IEntityView2 doesn't implement IList?

Sorry for the confusion. I meant to say that EntityView(2)<T> implements IList and not IList<T>. simple_smile (as it implements IBindingList, which implements IList and thus also ICollection. )

What kind of issues did you ran into when you passed it to a method which accepted an IList? There are a couple of methods of IList which aren't supported, like IList.this[index].Setter, as a view is a readonly object, you can't replace an entity on index X with another one.

Frans Bouma | Lead developer LLBLGen Pro