The full name of ORM is object/Relation Mapping, that is, object relationship ing. Since ORM is developed, it is inevitable to involve the relationship between objects.
Through the abstraction of object-oriented ideas, we can define the relationships between objects as follows:
- One-to-one
- Multiple-to-one (one-to-multiple)
- Many-to-many
We can easily create an enumeration for object relationships.
Public Enum Relation
{
None = 1 ,
Onetoworkflow,
Manytoone,
Onetoone,
Manytoyun
}
This relation enumeration will be used in relationattribute. For details, see lightweight ORM Development Series: attribute preparation.
Next, let's take a look at Cascade operations.
All mainstream databases support cascade operations. The following is a small example of cascade operations-cascade deletion.
Create Table
(
Id varchar ( 20 ) Primary key,
Password varchar ( 20 ) Not Null
)
Create Table B
(
ID Int Identity ( 1 , 1 ) Primary key,
Name varchar ( 50 ) Not Null ,
Userid varchar ( 20 ),
Foreign key (userid) references a (ID) on Delete Cascade
)
Table B creates the primary code ID corresponding to a for the external code userid, and declares cascading deletion.
Test data:
Insert a values ( ' 11 ' , ' Aaa ' )
Insert a values ( ' 23 ' , ' Aaa ' )
Insert B values ( ' Da ' , ' 11 ' )
Insert B values ( ' Das ' , ' 11 ' )
Insert B values ( ' WW ' , ' 23 ' )
The ID in Table A is deleted' 11 The USERID in Table B is 11 It is also automatically deleted by the database. This is Cascade deletion.
Delete Where ID = ' 11 '
Databases generally support cascade operations such as on update cascade and on Delete cascade.
If we can use these relationships well, we can achieve cascading deletion like Nhibernate.
Below is a cascade Enumeration
Public Enum Cascade
{
All,
Saveorupdate,
Delete,
None
}
ThisCascadeWill be used in relationattribute. For more information, see lightweight ORM Development Series: attribute preparation.
Well, today's discussion is here, half past ten. Good night, everybody!