Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using below code to search a particular string in multiple columns

C#
IEnumerable<UserProductDetailResult> _query
    = from eml in dc.UserProductDetails
      join zk in dc.ZeekUsers on eml.aspnet_User.UserId equals zk.UserId
      where eml.aspnet_User.LoweredUserName.Equals(strUserName.ToLower())
         && (eml.Username.Contains(strSearch)
             || eml.ProductURL.Contains(strSearch)
             || eml.Nickname.Contains(strSearch))
         && !eml.IsDeleted
         && eml.IsActive
      select new UserProductDetailResult
          {
            _userProductDetail = eml,
            _zeekUser = zk
          };


where dc is DataContext object. but this returns 0 results.
the query that is generated from above code is

SQL
SELECT [t0].[UPID], [t0].[UserId], [t0].[PID], [t0].[Nickname], [t0].[Username], [t0].[ProductURL], [t0].[StartDt], [t0].[EndDt], [t0].[IsActive], [t0].[InfoData], [t0].[SocialNetworkingData], [t0].[AnalyticKey], [t0].[ProfileID], [t0].[UseDefaultAd], [t0].[UseDefaultEmail], [t0].[IsDeleted], [t0].[CreateDt], [t0].[LastUpdateDt], [t1].[ID], [t1].[UserId] AS [UserId2], [t1].[AccountType], [t1].[FirstName], [t1].[LastName], [t1].[Phone], [t1].[Address1], [t1].[Address2], [t1].[City], [t1].[State], [t1].[ZIP], [t1].[CountryID], [t1].[NickName1], [t1].[Nickname2], [t1].[AlternameEmail], [t1].[ProfileImage], [t1].[ZeekIdStatus], [t1].[RefZeekUserId], [t1].[IsActive] AS [IsActive2], [t1].[FailureCount], [t1].[IsBlocked], [t1].[IsFirstVisit], [t1].[IsWizardPassed], [t1].[IPAddress], [t1].[TimeZoneID], [t1].[CreateDt] AS [CreateDt2], [t1].[LastUpdateDt] AS [LastUpdateDt2]
FROM [dbo].[UserProductDetails] AS [t0]
INNER JOIN [dbo].[ZeekUsers] AS [t1] ON ((
    SELECT [t2].[UserId]
    FROM [dbo].[aspnet_Users] AS [t2]
    WHERE [t2].[UserId] = [t0].[UserId]
    )) = [t1].[UserId]
INNER JOIN [dbo].[aspnet_Users] AS [t3] ON [t3].[UserId] = [t0].[UserId]
WHERE ([t3].[LoweredUserName] = 'username') AND (([t0].[Username] LIKE 'a') OR ([t0].[ProductURL] LIKE 'a') OR ([t0].[Nickname] like 'a')) AND (NOT ([t0].[IsDeleted] = 1)) AND ([t0].[IsActive] = 1)



As soon as remove below search lines it works and returns proper data
C#
&& (eml.Username.Contains(strSearch)
    || eml.ProductURL.Contains(strSearch)
    || eml.Nickname.Contains(strSearch))


but this doesn't allow me to search
Can anyone please tell me how should I proceed?
Posted
Comments
AndrewCharlz 13-Mar-14 23:48pm    
_query = _query.where(a => a.contains(str))

1 solution

C#
string[]  strsearch  =  { "abc" ,"xyz","pqr"};
IEnumerable<userproductdetailresult> _query
    = from eml in dc.UserProductDetails
      join zk in dc.ZeekUsers on eml.aspnet_User.UserId equals zk.UserId
      where eml.aspnet_User.LoweredUserName.Equals(strUserName.ToLower())
         && (strsearch.Any(val => eml.Username.Contains(val))
         && !eml.IsDeleted
         && eml.IsActive
      select new UserProductDetailResult
          {
            _userProductDetail = eml,
            _zeekUser = zk
          };
</userproductdetailresult>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900