© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
Alparslan~

✅ 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();

var existingCategory = await _context.Categories.AnyAsync(x =>
x.Name.ToUpperInvariant() == normalizedName &&
x.Id != categoryDto.Id);

if (existingCategory)
{
throw new InvalidOperationException("Aynı isimde bir kategori zaten var.");
}

var categoryEntity = _mapper.Map<Category>(categoryDto);
await _context.Categories.AddAsync(categoryEntity);
await _unitOfWork.SaveChangesAsync();
return _mapper.Map<CategoryDto>(categoryEntity);
}

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'.
1.PNG
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ System.Linq.Expressions custom expression
C#CC# / help
3y ago
System.InvalidOperationException: The LINQ expression 'DbSet<WorkingTask>() .Where(w => new Work
C#CC# / help
2y ago
Await Linq Expression
C#CC# / help
4y ago
MongoDB.Driver.Linq.ExpressionNotSupportedException: ' Expression not supported: i.ToClaim()
C#CC# / help
14mo ago