Using LINQ to objects to find subset of BO based on contents of another BO


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Any LINQ gurus ? Seems like a lot of working with collections really cries out for some solutions based on LINQ to objects when you already have list and bos etc with data and you want to manipulate them on the client side.



This seems worth exploring and while LINQ to SQL seems pretty unnecessary for a lot of stuff the ability to do linq
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yeah, LINQ is pretty cool, but very slow. If you have any extensive queries, however, I would recommend against this. If the query is small in nature, then go for it. LINQ goes through 4 XAML translations coming and going, thus the slownes. It is also very reflective, so thus other performance issues.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Yeah, I understand the caveats about performance. In this case I have about 20 records in one BO to be filtered against 20 in another. This seems like the most useful place for this kind of stuff ( not even contemplating LINQ to SQL )



The C# version of the suggestion is :



intlist would be my list of itemplateskey I want to use as a disqualifier for inclusion in my query of the TemplatesBO



var query = from bo in this.templatesBO1.getenumerable()

where !intList.Contains( bo.itemplateskey )

select bo.ikey;




or VB



Dim query = From bo In me.templatesbo1.Getenumerable() _

Where Not intList.Contains(bo.itemplateskey) _

Select bo.ikey




Does this look about right?



( re: my other two posts on this topics - is there a best non-LINQ good way to do this otherwise ?)

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Yup.  You are one smart fella (aside from rooting for the Browns Tongue...actually I am pulling for Brady Quinn myself w00t ), don't know why I brought up the other as you already had it figured out Wink

Yes, this is a great place to use LINQ and should not be a performance issue.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)Advanced StrataFrame User (928 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Here's what I did that seems to work and play well with SF BOs



_ExcludedTemplateKeys is a list of iTemplatekey (system.int32) obtained from another BO





Dim query = From bo In me.templatesbo1.Getenumerable() _

Where Not _ExcludedTemplateKeys.Contains(me.templatesbo1.ikey) _

Select Me.TemplatesBO1.ikey







Need to explicitly use me.TemplateBO1 rather than bo or the compiler complains about attempting to use late binding.



The resulting query can then be used in fillbyprimarykey if you pass it in converted from a list to an array



Me.TemplatesBO1.fillbyprimarykey(query.toarray())




This works, but ...



In this case I already have the TemplateBO1 filled with all records ( which I am using in the LINQ above ) and I would prefer to keep the thrashing local rather than do another pull from the back end.



For that reason, I'd like to set a filter on TemplateBO1 based on the list of keys ( if I could do that I wouldn't even need the LINQ query here but could just set a filter on TemplatesBO1 once I knew which keys to exclude ) rather than fill the TemplatesBO1 again (and perhaps have to fill it again with all records if I need to repeat the process)



So a solution that involves filtering the local datatable rather than refilling it from the backend would be preferred.



But



Me.TemplatesBO1.filter = "query.contains(ikey) = false"




and numerous variants give me the runtime error that I am trying to use an undefined function in a filter. (is there a way to define the function that the filter can use it - tried to create an outside function wrapping query.contains() that returned a boolean but got the same result when I used it in the filter string at runtime)



plan B : I would like to fill my checked listbox from TemplatesBO1 based on a subset as if the filter had been applied, if it is not practical to filter the BO itself based on a function.



In that approach, I can easily get a LINQ cursor from TemplatesBO on that criteria. How would I tell the checked listbox to copy data from the query result into it's data source??



or is there a way to fill the datasource of the checked list box with a filter condition without actually changing the filter on the BO



Sorry for these long stream of consciousness posts, but I think I'm right on the edge here of figuring out some techniques that are going to be really useful in munging data locally



I am doing a lot of wizards right now and there are a whole lot of BOs talking to each other. If I can nail down some best practices on this stuff I think this is going to be way easier than Fox ever was.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search