繁体   English   中英

通过实体框架检查SQL Server中表的内容

[英]checking contents of a table in SQL server by Entity Framework

我在SQL Server中有一个名为Users的表,其中保留了passwordemail和作为主键的UserID 然后在我的项目中,我有两种形式,第一种形式获取密码和用户名,然后如果表中存在输入的密码和电子邮件,它将连接到第二种形式,如果没有,则不会。 然后连接到银行,我正在使用实体框架。 这是我的连接字符串:

   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作为主键,但是我不知道如何编写UserID来获取所有行?现在它只获取第2

   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();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM