0

我是 fluent nhibernate 的新手,我遇到了一个问题我使用传统方法在 asp.net 中创建了一个登录控件我想使用 Fluent nhibernate 来升级我的代码,但我坚持使用它给出了我当前的代码以下

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con1"].ConnectionString);
        con.Open();
        SqlCommand cmdr = new SqlCommand("Select name,password From registration", con);
        SqlDataReader dr = cmdr.ExecuteReader();
        while (dr.Read())
        {
            if (txt_name.Text == dr[0].ToString() && txt_pass.Text == dr[1].ToString())
            {
                Session["new"] = txt_name.Text;
                Response.Redirect("logout.aspx");
            }
            else
            {
                label4.Text ="Invalid Username/Password";
            }
        }

    }

我的问题是如何使用流利的 nhibernate 执行相同的功能

4

1 回答 1

1
using NHibernate.Linq;

public ISession DbSession { get; set; } // set on each Beginrequest with ISessionFactory.OpenSession();

protected void Button1_Click(object sender, EventArgs e)
{
    var registrations = DbSession.Query<Registration>()
        .Where(registration => registration.Name == txt_name.Text)
        .ToList();

    if (registrations.Count == 0 || registrations[0].Password != txt_pass.Text)
    {
        label4.Text ="Invalid Username/Password";
    }
    else
    {
        Session["new"] = txt_name.Text;
        Response.Redirect("logout.aspx");
    }
}
于 2013-05-10T06:14:56.020 回答