SolvedPrivate

Need to add Where to this LINQ expression

Posted on 2014-02-12
10
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 19

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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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
 
LVL 63

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 63

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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