Как сделать проверку на то что в базе данных есть такая категория не учитывая регистр?

        [HttpPost]
        public IActionResult Add(Category category)
        {
            if (category != null)
            {
                if (!_db.Categories.Any(c => c.Name.Equals(category.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    _db.Categories.Add(category);
                    _db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return Content("Такая категория уже есть!");
        }

Падает с ошибкой
InvalidOperationException: The LINQ expression 'DbSet() .Any(c => c.Name.Equals( value: __category_Name_0, comparisonType: OrdinalIgnoreCase))' could not be translated. Additional information: Translation of the 'string.Equals' overload with a 'StringComparison' parameter is not supported. See https://go.microsoft.com/fwlink/?linkid=2129535 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.


Ответы (1 шт):

Автор решения: bubadev

Если я правильно понял надо просто сравнить не учитывая регистр. Попробуйте просто привести к нижнему или верхнему регистру. (ToLower и ToUpper)

if (!_db.Categories.Any(c => c.Name.TOLower() == category.Name.ToLower()))
→ Ссылка