Format Fluent API code from EF in Visual Studio 2022
07:18 16 Feb 2025

I am struggling to format code in C# in Visual Studio if it is written for the Fluent API of Entity Framework.

Something like this:

_db.ProdSmartSorts
    .Where(x => catIds.Contains((int)x.Product.CategoryId))
    .OrderBy(x => x.ProdSmartId)
    .Select(x => x.Product)
    .Include(p => p.Pictures.Where(pic => pic.IsCover))
    .Skip(prodCount * (pageNumber - 1))
    .Take(prodCount)
    .ToList();

What I want:

  • align all function calls, so each of them has the same spacing from the left
  • maybe just one function call per line
  • maybe indent .ThenInclude() further

What I have:

  • formatting code does not affect fluent code at all
  • I did not find any setting for this

Is there a (hidden) setting for this? Are there any extensions which solve this?

c# visual-studio entity-framework format