This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, Is there a way to sort EntityCollection? , kind of like List.Sort? I know there is EntityCollection.OrderBy(...) but I would like to sort EntityCollect itself. Thanks.
-chris
|
|
|
No, there isn't a way to sort EntityCollection. However, I believe you're using WPF (is that right?), in which case I believe you can use a CollectionView over the EntityCollection, and sort the view in the usual way using CollectionView.SortDescriptions. (The collection view will be a BindingListCollectionView so it should support sorting.) |
|
|
So is there way to use CollectionView instead of EntityCollection? Is having the wrapper around EntityCollection the only way? thanks. -chris
|
|
|
"Instead of"? No. A CollectionView is a view over a collection, not a collection in itself. It has to be underpinned by a collection, in this case the EntityCollection. But you can easily expose a CollectionView directly on your model if you don't have a separate viewmodel: partial class Customer { |
|
|
I meant to say if LS can generate CollectionView automatically as an option on one-to-many association. Thanks. -ck
|
|
|
There's no built-in way, but you could do it using a custom template. The template you'd need to tweak would be RelationshipProperties.vm, in the #if ($relationship.RelationshipType.ToString() == "OneToMany") section, and you'd want to add something like: $Translator.TranslateMethodAttributes($relationship.PropertyAttributes) System.Windows.Data.ICollectionView ${relationship.Name}View Not tested, no warranties, etc.! |
|
|
Cool! I guess learning about template would be very useful. I'll take a look when I find opportunity. Thanks. -chris |
|