I have to write a query in Fluent NHibernate for
Select * from Users where UserName = 'Abcd' AND Password = '123456'
How to create above query with session.CreateCriteria
Fluent NHibernate is a alternative Mapping framework to the default HBM files (Hibernate Mapping)
NHibernate itself offers different Querying API's like
For Criteria your query would be something along the lines of:
var users = session.CreateCriteria<Users>()
.Add(Restrictions.Eq("UserName", "Abcd"))
.Add(Restrictions.Eq("Password", "123456"))
.List<Users>();
Query:
var users = from u in session.Query<Users>()
where u.UserName == "Abcd"
&& u.Password == "123456"
select u;
or
var users = session.Query<Users>()
.Where(x => x.UserName == "Abcd" && u.Password == "123456");
QueryOver:
var users = session.QueryOver<Users>()
.Where(x => x.UserName == "Abcd")
.And(u.Password == "123456")
.List();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With