I am working with NHibernate and I get this code below:
public class User
{
public User()
{
public virtual int Id { get; set; }
public virtual IList<UserConfirmation> UserConfirmation { get; set; }
public virtual string Email;
}
public User()
{
UserConfirmation = new List<UserConfirmation>();
}
}
public class UserConfirmation
{
public virtual int Id { get; set; }
public virtual User { get; set; }
}
public class UserMap : ClassMap<User>
{
public UserMap()
{
Id(x => x.Id);
Map(x => x.Email);
HasMany(x => x.UserConfirmation)
.Inverse()
.Cascade.All();
Table("user");
}
}
public class UserConfirmationMap : ClassMap<UserConfirmation>
{
public UserConfirmationMap()
{
Id(x => x.Id);
References(x => x.User);
Table("user_confirmation");
}
}
But when I try to query over like this:
QueryOver<UserConfirmation>().Where(x => x.User.Email).Take(1).SingleOrDefault()
Than it says I do not have the property User.Email.
How can I solve this problem?
Problem is you are using x => x.User.Email
this should be done with another alias, which would be user
something like above should do the trick