SolvedPrivate

Need to add Where to this LINQ expression

Posted on 2014-02-12
10
61 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 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 39854307
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
ID: 39854319
return base.QueryOver(query).
                    WhereRestrictionOn(x => (x.DealerId) &&  (x => x.Status == true)).
                    OrderBy(x => x.SortOrder).Asc;
0
 

Author Comment

by:newbieweb
ID: 39854350
I tried these all prior to posting, but none works
0
 
LVL 40

Assisted Solution

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

Author Comment

by:newbieweb
ID: 39854516
It actually checks against an enumerate values, but the syntax is failing so I just used a book in this quersion.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 125 total points
ID: 39854587
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
ID: 39854605
So sorry, YES this is NHibernate.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39854610
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
ID: 39854615
AndRestrictionOn() solves the problem
0
 

Author Closing Comment

by:newbieweb
ID: 39854618
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

13 Experts available now in Live!

Get 1:1 Help Now