Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Proposal: Graph-based querying for Entity Framework

$
0
0
A while ago I've implemented an alternative way for querying complex data models. I called this Graph-based querying (GBQ) because rather then specifying relational queries in terms of joins, I use a simple graph language to define the shape of the graphs that should be retrieved from the database. This approach is very expressive when compared to the .Include mechanism of Entity Framework, because you can define graphs (including inheritance hierarchies) by the defining edges. Here is a simple example:
public class A
{
   public ICollection<B> Bs{get; set;}
}

public class B {
   public class C {get; set; }
}
public class C{
}
To query all A's and include their B's and for each B its C, the following graph shape can be used:
var shape = new EntityGraphShape(context)
   .Edge<A,B>(x=>x.Bs)
   .Edge<B,C>(x=>x.C);
shape.Load();
Apart from the fact that these graphs are very expressive, concise and type safe, they provide a pretty detailed description of the data that is to be queried. Because of this, it is possible to generate very efficient queries, even for huge data sets and complex data models. I've written a detailed performance comparison article at codeproject (http://www.codeproject.com/Articles/247254/Improving-Entity-Framework-Query-Performance-Using#_rating).

The implementation of GBQ nicely integrates with entity framework. It operates on entity models and derives its queries from the information contained in the conceptual and storage models. The resulting query is a collection of T-SQL queries. The resulting entities are added to the appropriate entity sets of entity framework. This way, GBQ forms an alternative query mechanism, that fully integrates with entity framework but easily outperforms the queries of entity framework.

I've created this query mechanism at a time the Entity Framework was not open source. Consequently, I was not able to integrate with entity framework as efficiently as could be possible. Furthermore, I'm not a SQL expert, so, it's not unlikely that the generated queries can be made even more efficient. I'm writing all this because now that entity framework is open source, there might be potential to optimize and improve the integration of GBQ and entity framework, and to make it into an add-on of entity framework for an alternative query mechanism that can improve the expressiveness of complex queries as well as their performance.

If you want to know about GBQ and the underlying entity graph concept have a look at:
I implemented GBQ for the June 2011 CTP of entity framework. Source code is available at http://entitygraph.codeplex.com.

I welcome any discussions on this.

Kind regards,
Merijn

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>