/// <summary> /// Defines a 'unique inside of DbSet' validator on the current rule builder. /// Validation will fail if the value of the property is not unique within the column /// of the given <paramref name="dbSet"/>. /// The column is specified by <paramref name="getColumnSelector"/>. /// </summary> /// <param name="ruleBuilder"></param> /// <param name="dbSet"></param> /// <param name="getColumnSelector"> /// Determines the column, with which we will compare the value of the property. /// </param> /// <typeparam name="TObject"> /// Type of object being validated /// </typeparam> /// <typeparam name="TProperty"> /// Type of property being validated /// </typeparam> /// <typeparam name="TEntity"> /// Type of entity, with which <paramref name="dbSet"/> operates /// </typeparam> /// <returns></returns> public static IRuleBuilderOptions <TObject, TProperty> UniqueInsideOfDbSetColumn <TObject, TProperty, TEntity>( this IRuleBuilder <TObject, TProperty> ruleBuilder, DbSet <TEntity> dbSet, Expression <Func <TEntity, TProperty> > getColumnSelector) where TObject : class where TEntity : class { return(ruleBuilder .MustAsync ( (newTitle, token) => EfCoreValidationHelpers.IsValueUniqueInsideOfDbSetColumnAsync (dbSet, getColumnSelector, newTitle, token) ) .WithMessage("{PropertyName} must be unique")); }