@@ -72,6 +72,7 @@ public class StudentCourse
7272## Defining a related collection
7373
7474You can get started with related collection through a two step process:
75+
75761 . Add collection definition
76772 . Add related collection entity picker and definition
7778
@@ -118,3 +119,48 @@ collectionConfig.Editor(editorConfig =>
118119{% hint style="info" %}
119120** Relation Config Alias:** The relation config alias must correspond to the related collection picker field alias! (e.g. ` studentsCourses ` )
120121{% endhint %}
122+
123+ ## Defining repository methods
124+
125+ ### ** IEnumerable<StudentCourse > GetRelationsByParentIdImpl<StudentCourse >(int parentId, string relationAlias)**
126+
127+ Retrieves the related collections based on the ID of the parent entity.
128+
129+ ``` csharp
130+ {
131+ var db = _scopeProvider .CreateScope ().Database ;
132+ var sql = db .SqlContext .Sql ()
133+ .Select (new [] { " StudentId" , " CourseId" } )
134+ .From (" StudentsCourses" )
135+ .Where ($" studentId = @0" , parentId );
136+
137+ var result = db .Fetch <StudentCourse >(sql );
138+
139+ return result ;
140+ }
141+ ```
142+
143+ ### ** StudentCourse SaveRelationImpl<StudentCourse >(StudentCourse entity)**
144+
145+ Adds a new related collection to the current parent entity.
146+
147+ ``` csharp
148+ {
149+ var db = _scopeProvider .CreateScope ().Database ;
150+
151+ var type = entity .GetType ();
152+ var studentId = type .GetProperty (" StudentId" ).GetValue (entity );
153+ var courseId = type .GetProperty (" CourseId" ).GetValue (entity );
154+
155+ // delete relation if exists
156+ db .Execute (" DELETE FROM StudentsCourses WHERE StudentId = @0 AND CourseId = @1" ,
157+ studentId ,
158+ courseId );
159+
160+ db .Execute (" INSERT INTO StudentsCourses (StudentId, CourseId) VALUES (@0, @1)" ,
161+ studentId ,
162+ courseId );
163+
164+ return entity ;
165+ }
166+ ```
0 commit comments