Hello!
NHibernate version:
2.0.0.Alpha1
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="BusinessObjects.DomainObjects.Position, BusinessObjects" table="Position" schema="dbo" lazy="true">
<id name="ID" access="property" column="ID" type="Int32" unsaved-value="0">
<generator class="native">
</generator>
</id>
<property name="Name" access="property" type="String">
<column name="Name" not-null="true"/>
</property>
<many-to-one name="BusinessUnit" access="property" class="BusinessObjects.DomainObjects.BusinessUnit, BusinessObjects" column="BusinessUnitID" />
<many-to-one name="PositionParent" access="property" class="BusinessObjects.DomainObjects.Position, BusinessObjects" column="ParentID" />
<many-to-one name="Role" access="property" class="BusinessObjects.DomainObjects.Role, BusinessObjects" column="RoleID" />
<many-to-one name="Team" access="property" class="BusinessObjects.DomainObjects.Team, BusinessObjects" column="TeamID" />
<bag name="Assigments" access="property" table="Assigment" lazy="true">
<key column="PositionID" />
<one-to-many class="BusinessObjects.DomainObjects.Assigment, BusinessObjects" />
</bag>
<bag name="DisabledPositionsForProcesses" access="property" table="DisabledPositionsForProcess" lazy="true">
<key column="PositionID" />
<one-to-many class="BusinessObjects.DomainObjects.DisabledPositionsForProcess, BusinessObjects" />
</bag>
<bag name="Employees" access="property" table="Employee" lazy="true">
<key column="PositionID" />
<one-to-many class="BusinessObjects.DomainObjects.Employee, BusinessObjects" />
</bag>
<bag name="PositionChild" access="property" table="Position" lazy="true">
<key column="ParentID" />
<one-to-many class="BusinessObjects.DomainObjects.Position, BusinessObjects" />
</bag>
<bag name="SubProcessInfoes" access="property" table="SubProcessInfo" lazy="true">
<key column="PositionID" />
<one-to-many class="BusinessObjects.DomainObjects.SubProcessInfo, BusinessObjects" />
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():session.Delete(entity);
Name and version of the database you are using:MS SQL 2005
-----------
I hope that full mapping files aren't nessesary. I have an entity, when I try to delete it, I don't want to delete and updates relationsof it, but...
From SQL Profiler:
Code:
exec sp_executesql N'UPDATE dbo.Assigment SET PositionID = null WHERE PositionID = @p0',N'@p0 int',@p0=5
go
exec sp_executesql N'UPDATE dbo.DisabledPositionsForProcess SET PositionID = null WHERE PositionID = @p0',N'@p0 int',@p0=5
go
exec sp_executesql N'UPDATE dbo.Employee SET PositionID = null WHERE PositionID = @p0',N'@p0 int',@p0=5
go
exec sp_executesql N'UPDATE dbo.Position SET ParentID = null WHERE ParentID = @p0',N'@p0 int',@p0=5
go
exec sp_executesql N'UPDATE dbo.SubProcessInfo SET PositionID = null WHERE PositionID = @p0',N'@p0 int',@p0=5
go
exec sp_executesql N'DELETE FROM dbo.Position WHERE ID = @p0',N'@p0 int',@p0=5
go
Why does it work in a such way? How can I prevent it?