LINQ generated NHibernate and Entity Framework SQL (JOIN)
This article has been migrated to its new home here: https://benperk.github.io/msdn/2012/2012-07-linq-generated-nhibernate-and-entity-framework-sql-join.html
In continuation of a previous blog which compared 2 simple SELECT statements between NHibernate and Entity Framework, I do the same with the joining of 2 tables together.
Figure 1 shows the LINQ to NHibernate query which selects all the data from the PostForNHibernate table, joins with the BlogForNHibernate table using the foreign key where the BloggerName is Benjamin Perkins.
Figure 1, LINQ to NHibernate JOIN with Lambda Expression
Figure 2 shows the data result and the generated SQL from the source code shown in Figure 1.
Figure 2, LINQ to NHibernate generated SQL – JOIN
Figure 3 shows the LINQ to Entities query which selects all the data from the Post table, joins with the Blog table using the foreign key where the BloggerName is Benjamin Perkins.
Figure 3, LINQ to Entities with Lambda expression
Figure 4 shows the data result and the generated SQL from the source code shown in Figure 3.
Figure 4, LINQ to Entities generated SQL – JOIN
The SQL queries are almost exact excluding the placement of the search variable ‘Benjamin Perkins’. I am almost convinced that the queries created by both NHibernate and Entity Framework are, at least at a simple level, the same.
I will perform some more tests with some Aggregates and commands like GROUP BY and ORDER BY and let you know the outcome.