开发者

Is this linq query efficient?

开发者 https://www.devze.com 2023-02-19 18:02 出处:网络
Is this linq query efficient? var qry = ((from member in this.ObjectContext.TreeMembers.Where(m => m.UserId == userId && m.Birthdate == null)

Is this linq query efficient?

    var qry = ((from member in this.ObjectContext.TreeMembers.Where(m => m.UserId == userId && m.Birthdate == null)
              select member.TreeMemberId).Except(from item in this.ObjectContext.FamilyEvents select item.TreeMemberId));


    var mainQry = from mainMember in this.ObjectContext.TreeMembers
                  where qry.Contai开发者_JAVA百科ns(mainMember.TreeMemberId)
                  select mainMember;

Will this be translated into multiple sql calls or just one? Can it be optimised? Basically I have 2 tables, I want to select those records from table1 where datetime is null and that record should not exist in table2.


The easiest way to find out if the query will make multiple calls is to set the .Log property of the data context. I typically set it to write to a DebugOutputWriter. A good example for this kind of class can be found here.

For a general way of thinking about it however, if you use a property of your class that does not directly map to a database field in a where clause or a join clause, it will typically make multiple calls. From what you have provided, it looks like this is not the case for your scenario, but I can't absolutely certain and suggest using the method listed above.

0

精彩评论

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