1

I need to transform this query to nhibernate linq

 IEnumerable<Account> accounts = from a in dc.Accounts
                                 where (a.FirstName + " " + a.LastName).Contains(SearchText) ||
                                        a.Email.Contains(SearchText) ||
                                        a.Username.Contains(SearchText)
                                 select a;

I tried with this but I"m stuck at the beginning so I need help.

IEnumerable<Account> accounts = NHSession.Query<Account>().Where(x=>x.FirstName)
1
  • 'I need help' is not a question. If you asked a specific question you would get much more helpful answers. Commented Feb 24, 2013 at 2:29

2 Answers 2

2

From the looks of your query you might want to spend a few min and read Ayende's post on Complex Searching found here.

Rather than using the Session Query or Detached Criteria - look into implementing this as a QueryOver. Then you can build the search criteria well ahead of the session call, then simply pass in the query to the session when you are finally ready to bring it up. Also don't forget Future Values and Paging for larger result sets:

Sign up to request clarification or add additional context in comments.

Comments

1

Query below will return IQueryable<Account> , you can either use it for further querying or evaluate to obtain results.

var accounts = NHSession.Query<Account>().Where(a=> (a.FirstName+" "+a.LastName).Contains(SearchText) || a.Email.Contains(SearchText) || a.Username.Contains(SearchText) ); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.