开发者

Limiting fields in Select statement generated by Linq to Castle ActiveRecord

开发者 https://www.devze.com 2023-01-07 18:01 出处:网络
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, i

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号