Quantcast
Channel: eXpandFramework RSS
Viewing all articles
Browse latest Browse all 861

BLOG by Dennis Garavsky: A more straightforward and convenient way to query data using LINQ with ObjectSpace

$
0
0
First of all, it is important to note that the capability to query data using LINQ has been available for a long time in the current version of XAF (or better said, in the underlying Entity Framework and XPO ORM libraries). So, this improvement is all about improving developer usability by exposing a helper method for the IObjectSpace interface representing one of the main XAF entities (learn more...). 

As noted in the corresponding SC ticket (you learn more on the current solution from here as well):

The IObjectSpace interface now declares the following method:

[C#]IQueryable<T>GetObjectsQuery<T>(BooleaninTransaction=false);
This method is implemented in the XPObjectSpaceEFObjectSpace and NonPersistentObjectSpace classes. 
The inTransaction parameter has effect in XPO only and enables the mode in which querying a data store for objects includes all in-memory changes into query results.
In the NonPersistentObjectSpace, the GetObjectsQuery method casts the collection of objects created in the ObjectsGetting event to IQueryable and returns the result.

For XPObjectSpace, this method just returns a new XPQuery<T> from the underlying Session, while for the EFObjectSpace, the GetObjectsQuery method returns a new instance of ObjectQuery<T> with the help of the associated DbContext.

I hope you will appreciate this minor improvement and it will save you from polluting your code by the casts to the XPObjectSpace/EFObjectSpace types to access the underlying ORM data context LINQ features.

Viewing all articles
Browse latest Browse all 861

Trending Articles