Click here to Skip to main content
14,241,236 members
Rate this:
Please Sign up or sign in to vote.
See more:
Im using LINQ to SQl and firing the query for login as follows
var result = from userlist in context.UserMasters
where userlist.UserName.Equals(username)
where userlist.UserPassword.Equals(pass,StringComparison.InvariantCulture)
select userlist;
if (result.ToList().Count > 0)
{
values = true;
}

method 'boolean equals system.string system.stringcomparison ' has no supported translation to sql


but it gives an eror as follows what should i do,i want to compare the password with case sensitive pls help
Posted
Updated 18-Jul-12 23:36pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Linq generates sql -query.. That means you cant use functions in you'r queryable. And since SQL server isn't case sensitive you have to do this in a slightly other way:

var result = from userlist in context.UserMasters
             where userlist.UserName.Equals(username)

// Maybe bether (if usernames are unique):
var result = context.UserMasters.SingleOrDefault(u=>u.UserName == username);

if(result == null){
   // Did not find any user(s)
}

// If you want a case sensitive password check
if(result.UserPassword == pass){
  // The password is correct
}

// If you don't
if(result.UserPassword.Equals(pass, StringComparison.InvariantCulture)){
  // The password is correct
}


I did answer the very same question some days ago. You should really read that answer for more in depth explanation. Linq to sql query for Password Field case sensitive[^]
   
v4
Comments
Mehdi Gholam 19-Jul-12 5:48am
   
My 5!
StianSandberg 19-Jul-12 5:50am
   
thx:)
sampath1750 19-Jul-12 6:03am
   
Thanks AlluvialDeposit
My vote also 5
StianSandberg 19-Jul-12 6:04am
   
you're welcome :)
Please mark as accepted if it works..

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100