I want to query one more property of the "User" entity. Basically I need to know, is it possible to extend the below statement to include something like this..
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower()) && (u => u.Email == email);
I know thats not correct but you get the idea, I want to check the user email as well as the username.
This is the current code..
public static bool IsDuplicateIdentity(string identity, string email, Type type)
{
using(ISession session = NHibernateHelper.SessionFactory().OpenSession())
using (ITransaction tx = session.BeginTransaction())
{
User user = null;
// the entity type is checked and then DB is queried to see if an object with that name and email exists
if (type.BaseType == typeof(User))
{
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower());
}
tx.Commit();
if (user != null)
{
return true;
}
else
{
return false;
}
}
}
Please note this is an ASP.net MVC 3 application.
Yes, you can combine them and you almost got it right. Try it like this:
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower() && u.Email == email);
Sure:
user = session.Query<User>()
.SingleOrDefault(u => u.Username.ToLower() == identity.ToLower()
&& u.Email == email);
Can't you just do this?:
user = session.Query<User>()
.SingleOrDefault(u =>
u.Username.ToLower() == identity.ToLower()
&& u.Email == email);
You can write the below code
user = session.Query<User>()
.where(u => u.Username.ToLower() == identity.ToLower() && u.Email == email).SingleOrDefault();
I want to query one more property of the "User" entity. Basically I need to know, is it possible to extend the below statement to include something like this..
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower()) && (u => u.Email == email);
I know thats not correct but you get the idea, I want to check the user email as well as the username.
This is the current code..
public static bool IsDuplicateIdentity(string identity, string email, Type type)
{
using(ISession session = NHibernateHelper.SessionFactory().OpenSession())
using (ITransaction tx = session.BeginTransaction())
{
User user = null;
// the entity type is checked and then DB is queried to see if an object with that name and email exists
if (type.BaseType == typeof(User))
{
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower());
}
tx.Commit();
if (user != null)
{
return true;
}
else
{
return false;
}
}
}
Please note this is an ASP.net MVC 3 application.
Yes, you can combine them and you almost got it right. Try it like this:
user = session.Query<User>().SingleOrDefault(u => u.Username.ToLower() == identity.ToLower() && u.Email == email);
Sure:
user = session.Query<User>()
.SingleOrDefault(u => u.Username.ToLower() == identity.ToLower()
&& u.Email == email);
Can't you just do this?:
user = session.Query<User>()
.SingleOrDefault(u =>
u.Username.ToLower() == identity.ToLower()
&& u.Email == email);
You can write the below code
user = session.Query<User>()
.where(u => u.Username.ToLower() == identity.ToLower() && u.Email == email).SingleOrDefault();
0 commentaires:
Enregistrer un commentaire