For this simple User class
public partial class Users
{
public long Id { get; set; }
public string User { get; set; }
public string Password { get; set; }
}
I have the WCF form to add new user working fine and checking to not allow duplicated User name
Now I have a WCF form for the logging in, 2 texbox (textBoxUser and password) and a button with this code:
private void buttonOK_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("I want to validate the user and password");
using (UserDBEntities db = new UserDBEntities())
{
if (db.Users.Any(o => o.User == textBoxUser.Text))
{
MessageBox.Show("The user " + textBoxUser.Text + " exist! Now I need to check if the password is right");
var userAccepted = db.Users.Find(textBoxUser.Text);
}
else
MessageBox.Show("User or password wrong. Try again!");
}
But the line
var userAccepted = db.Users.Find(textBoxUser.Text);
is not working - I keep getting an error:
ArgumentException was unhandled
An unhandled exception of type 'System.ArgumentException' occurred in EntityFramework.dll
Additional information: The type of one of the primary key values did not match the type defined in the entity. See inner exception for details.
even if User and textBoxUser.Text are strings.
And I don't know how to load the object from the database so I can check if the password is OK.
db.Users.First(u => u.User == textBoxUser.Text)will return the object the same waydb.Users.Any(u => u.User == textBoxUser.Text)will return if it exists