Further Linq enhancements
No edit summary
(Updated Edited template to July 12, 2025.)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<message>Write the content here to display this box</message>
Until now, it has been problematic to filter on type in Linq.
Until now, it has been problematic to filter on type in Linq.


The problem can be shown with this model:
This model shows the problem:
[[File:Linq.png|none|thumb|366x366px]]
[[File:Linq.png|none|thumb|366x366px]]


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


In Ocl2Ps, we would have done:<blockquote>''Class2.allInstances->select(a|((a.Class1.Attribute1 = '5') and (a.Name = '5A'))).Class1->FilterOnType(SomeSubClass)''</blockquote>Until now, MDriven Linq2Sql logic did not understand the Linq counterpart of FilterOnType – which is OfType<class>().  
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:
But now it does:
Line 26: Line 29:
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|2025}}

Latest revision as of 05:50, 20 January 2025

This page was created by Alexandra on 2018-12-02. Last edited by Edgar on 2025-01-20.

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.

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments