user1765862
user1765862

Reputation: 14205

nhibernate linq basics

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)

Upvotes: 1

Views: 172

Answers (2)

Bill Berry
Bill Berry

Reputation: 413

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:

Upvotes: 2

tchrikch
tchrikch

Reputation: 2468

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) ); 

Upvotes: 1

Related Questions