Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6188507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:14:37+00:00 2026-05-24T02:14:37+00:00

i have a query in SQL Declare @Id Int set @UserName = Null set

  • 0

i have a query in SQL

Declare @Id Int
set @UserName = Null
set @FullName = Null
Select * from tblPermission where (UserName= @UserName OR @UserName IS NULL) && (
FullName = @FullName OR @FullName IS NULL)

i m using Fluent nHibernate as ORM .

i m trying this:

 var Allusers = from u in session.Query<User>()
                               where u.UserName.Contains(UserName) || UserName == null
                               && u.FullName.Contains(FullName) || FullName == null
                               select u;

This linq query works fine for UserName but not working if UserName and FullName filters both have some value.
how to achieve this functionality in LINQ ? Any Idea?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:14:38+00:00Added an answer on May 24, 2026 at 2:14 am

    I would go with dynamically building the query:

    var Allusers = session.Query<User>();
    if (UserName != null)
        Allusers = Allusers.Where(u => u.UserName.Contains(UserName));
    if (FullName != null)
        Allusers = Allusers.Where(u => u.FullName.Contains(FullName));
    

    Since it’s a query, it won’t be executed until you enumerate it so chaining Where calls won’t execute it multiple times. Plus you’ll get a SQL query optimized for each case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql query as follows: Declare @DivisionNo INT SET @DivisionNo = 5117
I have the following SQL query: Declare @Total_SysDown as int, @Login_SysDown as int Set
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
Error SQL query: UPDATE `wfg_db`.`employee` SET `DOB` = (DECLARE@mm INT DECLARE@xm INT SET @mm
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have an SQL query that takes the following form: UPDATE foo SET flag=true
Say I have this great query in my stored procedure. Select * from Temp
I have created a sample query in sql server to parse data from xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.