Further Linq enhancements
No edit summary
(Automatically adding template at the end of the page.)
 
(One intermediate revision by the same user not shown)
Line 28: Line 28:
With this in place, the database takes care of all the filtering for us and returns the SomeSubClasses that have any Class2 with the correct criteria.
With this in place, the database takes care of all the filtering for us and returns the SomeSubClasses that have any Class2 with the correct criteria.
[[Category:Linq]]
[[Category:Linq]]
{{Edited|July|12|2024}}

Latest revision as of 15:34, 10 February 2024

Until now, it has been problematic to filter on type in Linq.

This model shows the problem:

Linq.png

If you want to find SomeSubClass that has a Class2 with a specific name:

var foo2 = (from v in EcoLinqExtender.PSQuery<Class2>(EcoSpace) 
     where (v.Class1.Attribute1 == "5" && v.Name == "5A") 
         select v.Class1)

But now, you also get Class1s that are not of SomeSubClass.That is a problem in certain situations.

In Ocl2Ps, we would have done:

Class2.allInstances->select(a|((a.Class1.Attribute1 = '5') and (a.Name = '5A'))).Class1->FilterOnType(SomeSubClass)

Until now, MDriven Linq2Sql logic did not understand the Linq counterpart of FilterOnType – which is OfType<class>().

But now it does:

var foo2 = (from v in EcoLinqExtender.PSQuery<Class2>(EcoSpace) 
       where (v.Class1.Attribute1 == "5" && v.Name == "5A") 
           select v.Class1).OfType<SomeSubClass>()

With this in place, the database takes care of all the filtering for us and returns the SomeSubClasses that have any Class2 with the correct criteria.

This page was edited 92 days ago on 02/10/2024. What links here