@@ -173,4 +173,166 @@ public static bool CanSetConstraintName(
173173 string ? name ,
174174 bool fromDataAnnotation = false )
175175 => relationship . CanSetAnnotation ( RelationalAnnotationNames . Name , name , fromDataAnnotation ) ;
176+
177+ /// <summary>
178+ /// Configures whether the foreign key constraint is excluded from migrations
179+ /// when targeting a relational database.
180+ /// </summary>
181+ /// <remarks>
182+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
183+ /// </remarks>
184+ /// <param name="referenceCollectionBuilder">The builder being used to configure the relationship.</param>
185+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
186+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
187+ public static ReferenceCollectionBuilder ExcludeFromMigrations (
188+ this ReferenceCollectionBuilder referenceCollectionBuilder ,
189+ bool excluded = true )
190+ {
191+ referenceCollectionBuilder . Metadata . SetIsExcludedFromMigrations ( excluded ) ;
192+
193+ return referenceCollectionBuilder ;
194+ }
195+
196+ /// <summary>
197+ /// Configures whether the foreign key constraint is excluded from migrations
198+ /// when targeting a relational database.
199+ /// </summary>
200+ /// <remarks>
201+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
202+ /// </remarks>
203+ /// <param name="referenceCollectionBuilder">The builder being used to configure the relationship.</param>
204+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
205+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
206+ /// <typeparam name="TEntity">The principal entity type in this relationship.</typeparam>
207+ /// <typeparam name="TRelatedEntity">The dependent entity type in this relationship.</typeparam>
208+ public static ReferenceCollectionBuilder < TEntity , TRelatedEntity > ExcludeFromMigrations < TEntity , TRelatedEntity > (
209+ this ReferenceCollectionBuilder < TEntity , TRelatedEntity > referenceCollectionBuilder ,
210+ bool excluded = true )
211+ where TEntity : class
212+ where TRelatedEntity : class
213+ => ( ReferenceCollectionBuilder < TEntity , TRelatedEntity > ) ExcludeFromMigrations (
214+ ( ReferenceCollectionBuilder ) referenceCollectionBuilder , excluded ) ;
215+
216+ /// <summary>
217+ /// Configures whether the foreign key constraint is excluded from migrations
218+ /// when targeting a relational database.
219+ /// </summary>
220+ /// <remarks>
221+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
222+ /// </remarks>
223+ /// <param name="referenceReferenceBuilder">The builder being used to configure the relationship.</param>
224+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
225+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
226+ public static ReferenceReferenceBuilder ExcludeFromMigrations (
227+ this ReferenceReferenceBuilder referenceReferenceBuilder ,
228+ bool excluded = true )
229+ {
230+ referenceReferenceBuilder . Metadata . SetIsExcludedFromMigrations ( excluded ) ;
231+
232+ return referenceReferenceBuilder ;
233+ }
234+
235+ /// <summary>
236+ /// Configures whether the foreign key constraint is excluded from migrations
237+ /// when targeting a relational database.
238+ /// </summary>
239+ /// <remarks>
240+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
241+ /// </remarks>
242+ /// <param name="referenceReferenceBuilder">The builder being used to configure the relationship.</param>
243+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
244+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
245+ /// <typeparam name="TEntity">The entity type on one end of the relationship.</typeparam>
246+ /// <typeparam name="TRelatedEntity">The entity type on the other end of the relationship.</typeparam>
247+ public static ReferenceReferenceBuilder < TEntity , TRelatedEntity > ExcludeFromMigrations < TEntity , TRelatedEntity > (
248+ this ReferenceReferenceBuilder < TEntity , TRelatedEntity > referenceReferenceBuilder ,
249+ bool excluded = true )
250+ where TEntity : class
251+ where TRelatedEntity : class
252+ => ( ReferenceReferenceBuilder < TEntity , TRelatedEntity > ) ExcludeFromMigrations (
253+ ( ReferenceReferenceBuilder ) referenceReferenceBuilder , excluded ) ;
254+
255+ /// <summary>
256+ /// Configures whether the foreign key constraint is excluded from migrations
257+ /// when targeting a relational database.
258+ /// </summary>
259+ /// <remarks>
260+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
261+ /// </remarks>
262+ /// <param name="ownershipBuilder">The builder being used to configure the relationship.</param>
263+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
264+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
265+ public static OwnershipBuilder ExcludeFromMigrations (
266+ this OwnershipBuilder ownershipBuilder ,
267+ bool excluded = true )
268+ {
269+ ownershipBuilder . Metadata . SetIsExcludedFromMigrations ( excluded ) ;
270+
271+ return ownershipBuilder ;
272+ }
273+
274+ /// <summary>
275+ /// Configures whether the foreign key constraint is excluded from migrations
276+ /// when targeting a relational database.
277+ /// </summary>
278+ /// <remarks>
279+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
280+ /// </remarks>
281+ /// <param name="ownershipBuilder">The builder being used to configure the relationship.</param>
282+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
283+ /// <returns>The same builder instance so that multiple calls can be chained.</returns>
284+ /// <typeparam name="TEntity">The entity type on one end of the relationship.</typeparam>
285+ /// <typeparam name="TDependentEntity">The entity type on the other end of the relationship.</typeparam>
286+ public static OwnershipBuilder < TEntity , TDependentEntity > ExcludeFromMigrations < TEntity , TDependentEntity > (
287+ this OwnershipBuilder < TEntity , TDependentEntity > ownershipBuilder ,
288+ bool excluded = true )
289+ where TEntity : class
290+ where TDependentEntity : class
291+ => ( OwnershipBuilder < TEntity , TDependentEntity > ) ExcludeFromMigrations (
292+ ( OwnershipBuilder ) ownershipBuilder , excluded ) ;
293+
294+ /// <summary>
295+ /// Configures whether the foreign key constraint is excluded from migrations
296+ /// when targeting a relational database.
297+ /// </summary>
298+ /// <remarks>
299+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
300+ /// </remarks>
301+ /// <param name="relationship">The builder being used to configure the relationship.</param>
302+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
303+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
304+ /// <returns>
305+ /// The same builder instance if the configuration was applied,
306+ /// <see langword="null" /> otherwise.
307+ /// </returns>
308+ public static IConventionForeignKeyBuilder ? ExcludeFromMigrations (
309+ this IConventionForeignKeyBuilder relationship ,
310+ bool ? excluded ,
311+ bool fromDataAnnotation = false )
312+ {
313+ if ( ! relationship . CanSetExcludeFromMigrations ( excluded , fromDataAnnotation ) )
314+ {
315+ return null ;
316+ }
317+
318+ relationship . Metadata . SetIsExcludedFromMigrations ( excluded , fromDataAnnotation ) ;
319+ return relationship ;
320+ }
321+
322+ /// <summary>
323+ /// Returns a value indicating whether the foreign key constraint exclusion from migrations can be set
324+ /// from the current configuration source.
325+ /// </summary>
326+ /// <remarks>
327+ /// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
328+ /// </remarks>
329+ /// <param name="relationship">The builder being used to configure the relationship.</param>
330+ /// <param name="excluded">A value indicating whether the foreign key constraint is excluded from migrations.</param>
331+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
332+ /// <returns><see langword="true" /> if the configuration can be applied.</returns>
333+ public static bool CanSetExcludeFromMigrations (
334+ this IConventionForeignKeyBuilder relationship ,
335+ bool ? excluded ,
336+ bool fromDataAnnotation = false )
337+ => relationship . CanSetAnnotation ( RelationalAnnotationNames . IsForeignKeyExcludedFromMigrations , excluded , fromDataAnnotation ) ;
176338}
0 commit comments