✅ System.InvalidOperationException: The LINQ expression
Hello guys. I'm writing a blog API, and in the process of adding a category, I want the first letter of the value in my DTO object to always be capitalized and added to the database in that format. I've tried many attempts, but I keep getting errors, and I haven't been able to find a solution even with AI. If you can help, I'd appreciate it.
CategoryRepo: public async Task<CategoryDto> CreateCategoryAsync(CategoryDto categoryDto) { categoryDto.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(categoryDto.Name);
var normalizedName = categoryDto.Name.Substring(0, 1).ToUpperInvariant() + categoryDto.Name.Substring(1).ToLowerInvariant();
Error : System.InvalidOperationException: The LINQ expression 'DbSet<Category>()\r\n .Any(c => c.Name.Equals(\r\n value: normalizedName_0, \r\n comparisonType: OrdinalIgnoreCase) && c.Id != categoryId_1)' 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'.