通过Entity Framework检查SQL Server中表的内容

问题描述 投票:0回答:1

我有一个名为Usersin SQL服务器的表,它保留了passwordemailUserID这是主键。然后在我的项目中我有两个表单,第一个表单获取密码和用户名称,然后如果输入密码和电子邮件存在于表中它连接到第二个表单,如果不是,它不连接。然后连接到银行我正在使用实体框架。这是我的连接字符串:

   int UserID = 2;
        UsersEntities db = new UsersEntities();
        var find = db.CalUsers.Find(UserID);
        if (find.Email == txtEmail.Text && find.Password == txtPassword.Text)
        {
            SmallCalculator example = new SmallCalculator();
            example.ShowDialog();
        }

我知道我必须使用UserID作为主键但我不知道如何写UserIDto获取所有行?现在它只是得到row2

c# sql-server entity-framework windows-forms-designer
1个回答
0
投票
   int UserID = 2; // you don't actually know this value since user is not giving it to you
    UsersEntities db = new UsersEntities();

    //hopefully email address has a unique constraint:
    var find = db.CalUsers.FirstOrDefault(x=>x.Email == txtEmail.Text.Trim());

    if(find == null) return; //do something else

    if (find.Email == txtEmail.Text && find.Password == txtPassword.Text)
    {
        SmallCalculator example = new SmallCalculator();
        example.ShowDialog();
    }
© www.soinside.com 2019 - 2024. All rights reserved.