I'm using ActiveRecord and LinqToActiveRecord to query my database. The problem is, that the generated SQL statement from my LINQ expressi开发者_Go百科on always tries to select all possible fields, including joined tables, when this is not needed. For example, I have these database tables:
Table: MasterTable
Id (int)
ChildId (int) <- references a record in the Child table
Table: ChildTable
Id (int)
ChildName (varchar)
Now I want to query all Master records of which the referenced Child record contains ChildName "Tijn":
var myList = (from master in MasterTable.Queryable
where master.Child.ChildName == "Tijn"
select master).ToList();
The generated SQL statement tries to select not only all Master fields, but the joined Child fields too! When I try the same using HQL:
select master from MasterTable master where master.Child.ChildName = 'Tijn'
the generated SQL statement only includes the master fields, like I wanted to.
So, to be short: How can I 'limit' / 'constrain' the tables of which fields are selected in LINQtoActiveRecord / LINQtoNHibernate? Some kind of 'projection' or extended 'Select' method?
精彩评论