|
| 1 | +using System.Runtime.CompilerServices; |
| 2 | +using Microsoft.EntityFrameworkCore.Infrastructure; |
| 3 | + |
| 4 | +namespace Thinktecture.EntityFrameworkCore; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// Entity with provided name and/or type is not part of current <see cref="DbContext"/>. |
| 8 | +/// </summary> |
| 9 | +public class EntityTypeNotFoundException : ArgumentException |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Initializes new instance of <see cref="EntityTypeNotFoundException"/>. |
| 13 | + /// </summary> |
| 14 | + /// <param name="entityName">Entity name not found in the model of current <see cref="DbContext"/>.</param> |
| 15 | + /// <param name="paramName">The name of the parameter.</param> |
| 16 | + public EntityTypeNotFoundException( |
| 17 | + string entityName, |
| 18 | + [CallerArgumentExpression("entityName")] string? paramName = null) |
| 19 | + : base($"The provided name '{entityName}' is not part of the provided Entity Framework model.", paramName) |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Initializes new instance of <see cref="EntityTypeNotFoundException"/>. |
| 25 | + /// </summary> |
| 26 | + /// <param name="entityType">The type of the entity not found in the model of current <see cref="DbContext"/>.</param> |
| 27 | + /// <param name="paramName">The name of the parameter.</param> |
| 28 | + public EntityTypeNotFoundException( |
| 29 | + Type entityType, |
| 30 | + [CallerArgumentExpression("entityType")] string? paramName = null) |
| 31 | + : base($"The provided type '{entityType.ShortDisplayName()}' is not part of the provided Entity Framework model.", paramName) |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Initializes new instance of <see cref="EntityTypeNotFoundException"/>. |
| 37 | + /// </summary> |
| 38 | + /// <param name="entityName">Entity name not found in the model of current <see cref="DbContext"/>.</param> |
| 39 | + /// <param name="entityType">The type of the entity not found in the model of current <see cref="DbContext"/>.</param> |
| 40 | + /// <param name="entityNameParamName">The name of the parameter.</param> |
| 41 | + public EntityTypeNotFoundException( |
| 42 | + string entityName, |
| 43 | + Type entityType, |
| 44 | + [CallerArgumentExpression("entityName")] string? entityNameParamName = null) |
| 45 | + : base($"The provided name '{entityName}' and the type '{entityType.ShortDisplayName()}' were not part of the provided Entity Framework model.", entityNameParamName) |
| 46 | + { |
| 47 | + } |
| 48 | +} |
0 commit comments