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

  • SEARCH
  • Home
  • 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 3495926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:11:11+00:00 2026-05-18T12:11:11+00:00

I have a screen in my project Enquiry where I user can perform 2

  • 0

I have a screen in my project ” Enquiry” where I user can perform 2 kinds of search.I cannot figure out how to do a “like” or “And or is null” in Linq to entity.

  1. Simple Search ( Search in all fields using “Like” operator)
  2. Advanced Advanced Search (Use “And” Operator)

So lets take these 3 tables and make up a noddy example.

  1. Customer Table (CustomerID,Name,Surname)
  2. Address(AddressID,Street,City)
  3. CustomerOrder (OrderID,OrderName)

Basic search :
this is how I would do it in Sql

  SELECT TOP (100) C.Name,C.Surname,CA.Street,CA.City,CO.OrderName
  FROM Customer C 
  LEFT JOIN CustomerAddress CA ON C.CustomerID=CA.CustomerID
  LEFT JOIN CustomerOrders CO ON C.CustomerID=CA.CustomerID   
  WHERE  (C.CustomerID LIKE '%' + @SearchText + '%'  
  OR C.Surname LIKE '%' + @SearchText + '%' 
  OR C.Name LIKE '%' + @SearchText + '%'        
  OR CA.Street LIKE '%' + @SearchText + '%'
  OR CA.City LIKE '%' + @SearchText + '%'
  OR  CO.OrderName LIKE '%' + @SearchText + '%') )

Advanced Search

This my sql where clause

    WHERE  (C.CustomerID =@CustomerID or @CustomerID ISNULL  
    AND C.Surname =@Surname or @Surname ISNULL
    AND C.Name=@Name or @Name ISNULL        
    AND CA.Street =@Street or @Street ISNULL
    AND CA.City =@City or @City ISNULL
    AND  CO.OrderName =@OrderName or @OrderName ISNULL)
    AND ((ModifiedDate BETWEEN ISNULL(convert(varchar,@FromDate,101),'01/01/1901')
    AND ISNULL(convert(varchar,@ToDate,101),'12/31/9999'))

How do you do Likes or and or is null in entity framework?

thanks a lot!

  • 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-18T12:11:12+00:00Added an answer on May 18, 2026 at 12:11 pm

    For LIKE, you can use Contains, StartsWith, or EndsWith. For IS NULL, use == null.

    Example:

    var list = from p in Products
               where (p.Description.Contains("v") && p.Description.StartsWith("C"))
                        || p.MFRCode == "TOYOTA"
                        || p.Universal == null                   
               select p;
    

    will cause EF to generate this SQL:

    SELECT 
    [Extent1].[MFRCode] AS [MFRCode], 
    [Extent1].[MFRProductID] AS [MFRProductID], 
    [Extent1].[Universal] AS [Universal], 
    [Extent1].[Description] AS [Description]
    FROM [dbo].[Products] AS [Extent1]
    WHERE (([Extent1].[Description] LIKE N'%v%') AND ([Extent1].[Description] LIKE N'C%')) OR (N'TOYOTA' = [Extent1].[MFRCode]) OR ([Extent1].[Universal] IS NULL)
    

    and produce these results:

    alt text

    Edit

    I used LINQPad to generate these results. It’s a great tool, free to use (there’s an option to purchase an Intellisense feature), and definitely worth a look if you’d like to experiment with different LINQ queries and see the SQL that EF is generating (it’s good for general LINQ experimentation and quickly trying out simple code as well).

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

Sidebar

Related Questions

I have a simple VS setup project. On the first screen user inputs database
I have a screen in my project that contains 3 UIScrollView . These scrollviews
I have made a project in which i have added a splash screen by
I have a screen with pivot functionality, and I'd very much like just one
I have a screen where you can enable/disable modules for my Android application. For
I have a project in which I prefer only display full screen mode in
I have a Splash Screen for an Android Project in which I have to
I´m having a problem with my Android Project. I have a screen filling custom
I would like to dim-down my screen in my project as im working on.
In a Visual Studio Setup & Deployment Project, I can design the user interface

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.