I have a user class that has username which I need to save in the DB encrypted
public abstract class User
{
public virtual int Id { get; protected set; }
public virtual string Username
{
get
{
return _encryptionProvider.Decrypt(SecuredUsername);
}
protected set
{
SecuredUsername = _encryptionProvider.Encrypt(value);
}
}
[Obsolete("Use the 'Username' property -- this property is only to be used by NHibernate")]
protected virtual string SecuredUsername { get; set; }
}
I mapped the User entity as below:
public class UserMapping : ClassMap<User>
{
public UserBaseMapping()
{
Id(user => user.Id).GeneratedBy.HiLo("100");
Map(Reveal.Member<UserBase>("SecuredUsername")).Unique();
}
}
It worked fine until I had to write some LINQ statement.
User user = _session.QueryOver<User>().Where(x => x.Username == "Hamza").SingleOrDefault();
The problem here is that when LINQ translates above statement to SQL it becomes something like this: Select * from [dbo].[User] Where Username like 'Hamza'
And as you might noticed there is no column called username in the table but securedusername and it contains the encrypted value Can anyone please help me solving this issue, I need to be able to query using LINQ.