Hello people.
User.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="hiddenDomain"
namespace="hidden.Domain.Entities.Users">
<class name="User" table="`Users`" lazy="false" where="`Active` = 1">
<id name="Id" column="`ID`">
<generator class="identity"/>
</id>
<property name="Username" column="`Username`" unique="true" length="100" not-null="true"/>
<property name="Password" column="`Password`" length="40" not-null="true"/>
<property name="Email" column="`Email`" length="200" not-null="true"/>
<property name="Realname" column="`Realname`" length="100" not-null="true"/>
<property name="Phone" column="`Phone`" length="100" not-null="true"/>
<property name="RegisterDate" column="`RegisterDate`" not-null="true"/>
<property name="IsActive" column="`Active`" not-null="true"/>
<bag name="Roles" lazy="false" cascade="all" table="`UserHasrole`">
<key column="`User`"/>
<many-to-many class="Role" column="`Role`" lazy="false"/>
</bag>
</class>
</hibernate-mapping>
Nothing strange, works perfectly fine.
The thing is, there are one case when I don't want that WHERE clause. When I insert a new User I check if there's already a user with that email and username. But I want to check if there's an inactive user with that username and email too. So how can I tell NHibernate to ignore the where clause for this query?
Code to select...
Code:
var criteria = session.CreateCriteria ( typeof ( User ) )
.Add ( Restrictions.And ( Restrictions.Eq ( "IsActive", false ), Restrictions.Eq ( "Email", email ) ) );
return criteria.UniqueResult<User> ( );
Generated SQL:
Code:
SELECT this_.[ID] as ID1_0_0_, this_.[Username] as Username2_0_0_, this_.[Password] as Password3_0_0_, this_.[Email] as Email4_0_0_, this_.[Realname] as Realname5_0_0_, this_.[Phone] as Phone6_0_0_, this_.[RegisterDate] as Register7_0_0_, this_.[Active] as Active8_0_0_ FROM [Users] this_ WHERE ( this_.[Active] = 1) AND (this_.[Active] = @p0 and this_.[Username] = @p1); @p0 = 'False', @p1 = 'Erik'
Thanks in advance!