0
votes

I'm new to fluent nhibernate and I'm stuck with a problem I created a login control in asp.net using tradition methods And I want to use Fluent nhibernate for upgrade my code and I'm stuck with it my current code is given below

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";
            }
        }

    }

and my question is how to do the same function using fluent nhibernate

1

1 Answers

1
votes
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");
    }
}