SolvedPrivate

Need to add Where to this LINQ expression

Posted on 2014-02-12
10
60 Views
Last Modified: 2016-02-10
return base.QueryOver(query).
                    WhereRestrictionOn(x => x.DealerId).
                    OrderBy(x => x.SortOrder).Asc;


I need to add Where(x  => x.Status == true)

but do not know how to ad this correctly since there is already a call to WhereRestrictionOn
0
Comment
Question by:newbieweb
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
Comment Utility
Not sure if this will work:
WhereRestrictionOn(x => x.DealerId && x.Status == true)

but you can chain the where:
return base.QueryOver(query).
                    WhereRestrictionOn(x => x.DealerId).
                    Where(x => x.Status == true).
                    OrderBy(x => x.SortOrder).Asc;
0
 
LVL 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 125 total points
Comment Utility
return base.QueryOver(query).
                    WhereRestrictionOn(x => (x.DealerId) &&  (x => x.Status == true)).
                    OrderBy(x => x.SortOrder).Asc;
0
 

Author Comment

by:newbieweb
Comment Utility
I tried these all prior to posting, but none works
0
 
LVL 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
Comment Utility
does status have a value?  and is it actually "true" or is it 1 ?
0
 

Author Comment

by:newbieweb
Comment Utility
It actually checks against an enumerate values, but the syntax is failing so I just used a book in this quersion.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 125 total points
Comment Utility
A couple of questions. Is this using NHibernate?

Is the query you posted complete? For example the examples I have seen have something like this:

WhereRestrictionOn(x => x.DealerId).IsBetween(2).And(8)
0
 

Author Comment

by:newbieweb
Comment Utility
So sorry, YES this is NHibernate.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Also if your original query is actually working then did you try putting the Where before WhereRestrictionOn as shown below?

return base.QueryOver(query).
            Where(x  => x.Status == true).
            WhereRestrictionOn(x => x.DealerId).
            OrderBy(x => x.SortOrder).Asc;

Open in new window

0
 

Author Comment

by:newbieweb
Comment Utility
AndRestrictionOn() solves the problem
0
 

Author Closing Comment

by:newbieweb
Comment Utility
thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now