Not sure how to proceed with NHibernate removal

I almost do not know how to proceed when uninstalling. My problem is that if the category is related to the problem and I try to remove it from the project, I should not do this.

How can i do this? Help me please.

I have 3 tables, problem, project, category

These relationships are as follows: 1. A project can have many problems, a problem is associated with only one project 2. A problem can have only one category 3. A project can have one or more categories

Issue.hbm.xml is as follows:

 <id name="id" type="Int32" unsaved-value="0" access="field">
  <column name="ID" length="4" sql-type="int" not-null="true" unique="true" index="PK_Issue"/>
  <generator class="native" />
</id>
<many-to-one name="Project" class="API.Project, API">
  <column name="ProjectID" length="4" sql-type="int" not-null="false"/>
</many-to-one>
<many-to-one name="Category" class="API.Category, API">
  <column name="CategoryID" length="4" sql-type="int" not-null="false"/>
</many-to-one>

project.hbm.xml

<id name="id" type="Int32" unsaved-value="0" access="field">
  <column name="ID" length="4" sql-type="int" not-null="true" unique="true" index="PK_Project"/>
  <generator class="native" />
</id>
<property name="Name" type="String">
  <column name="Name" length="200" sql-type="varchar" not-null="true" unique="true" index="IX_Project_Name"/>
</property>

category.hbm.xml

<id name="id" type="Int32" unsaved-value="0" access="field">
      <column name="ID" sql-type="int" not-null="true" unique="true" index="PK_Category"/>
      <generator class="native" />
    </id>
    <property name="Name" type="String">
      <column name="Name" length="50" sql-type="varchar" not-null="true" unique="true" index="IX_Category"/>
    </property>
    <many-to-one name="Project" class="API.Project, API" >
      <column name="ProjectID" length="4" sql-type="int" not-null="false"/>
    </many-to-one>
+3
source share
2 answers

, ? ( ). , , .

. issue.hbm.xml :

<id name="id" type="Int32" unsaved-value="0" access="field"> 
  <column name="ID" length="4" sql-type="int" not-null="true" unique="true" index="PK_Issue"/> 
  <generator class="native" /> 
</id> 
<many-to-one name="Project" class="API.Project, API" foreign-key="FK_Issue_Project"> 
  <column name="ProjectID" length="4" sql-type="int" not-null="false"/> 
</many-to-one> 
<many-to-one name="Category" class="API.Category, API" foreign-key="FK_Issue_Category"> 
  <column name="CategoryID" length="4" sql-type="int" not-null="false" /> 
</many-to-one>

FK, , - , , , , .

NHibernate FK, :)

EDIT:

OOPs - "--", "". . .

0

IMO, - , .

. , , , - . NH ORM. - , . , NH.

, .

, . , ProjectID . ( NH , , , ).

Off topic: sql-. NH . : ( ). () ExportSchema, . .

+1

Source: https://habr.com/ru/post/1758345/


All Articles