Repository: riok/mapperly (2026-07-06T09:17:03Z)

Issue:
elevate default severity of RMG068 from info to warning (queryable projection's user implemented mapping not inlinable)
**Is your feature request related to a problem? Please describe.**
When using EF Core `IQueryable` mapping projections, sometimes user-defined mapping methods can not be inlined which causes EF Core to skip generating SQL queries for query projection but instead loads all columns and all related entities and executes the projection client-side.

**Describe the solution you'd like**
When user-defined mapping methods can not be inlined into `IQueryable`-projections, a compile warning (which can be treated as error) prevents unintentional client-side evaluations.

```csharp
[Mapper]
public static partial class PersonDtoMapper
{
    private static string MapFullName(PersonDbo src)
    {
        // this renaming prevents inlining
        var source = src;
        return source.FirstName + " " + source.LastName;
    }

    // Expected a compile warning here that MapFullName could not be inlined to MapToPersonDto() expression
    [MapPropertyFromSource(nameof(UserDto.FullName), Use = nameof(MapFullName))]
    private static partial PersonDto MapToPersonDto(PersonDbo src);
    public static partial Expression<Func<PersonDbo, PersonDto>> MapToPersonDto();
}
```

**Describe alternatives you've considered**
Always inspect generated projection after any changes.

**Additional context**



Discussion:
I think this is already supported via diagnostic `RMG068`, no? It has a default severity of info, which you can increase through editorconfig (`dotnet_diagnostic.RMG068.severity = error`).
Why isn't it warning by default?
Fair point, I think warning as a default makes more sense. This would be a breaking change, but as we are working on 5.0 we can change this with the 5.0 release.



Patch:
diff --git a/docs/docs/breaking-changes/5-0.md b/docs/docs/breaking-changes/5-0.md
index 7a636b2c00..dc21c2fef4 100644
--- a/docs/docs/breaking-changes/5-0.md
+++ b/docs/docs/breaking-changes/5-0.md
@@ -21,6 +21,7 @@ description: How to upgrade to Mapperly 5.0 and a list of all its breaking chang
 - `AllowNull` attributes are now respected for fields, properties and constructor parameters when writing values.
 - Copy constructors are no longer selected over constructors annotated with `[MapperConstructor]` or when `[MapProperty]` configurations are present.
 - Generic and runtime target type mappings now correctly match derived types handled by a child `[MapDerivedType]` mapping.
+- The default severity of `RMG068` (cannot inline user implemented queryable expression mapping) has been raised from info to warning, see below.
 
 ## Inaccessible members from other assemblies included
 
@@ -327,3 +328,18 @@ public partial global::FruitDto MapDerivedTypes(global::Fruit source)
     };
 }
 ```
+
+## `RMG068` default severity raised to warning
+
+When Mapperly cannot inline a user-implemented mapping method into an `IQueryable` projection,
+it reports `RMG068`. Non-inlined method invocations can lead to more data being loaded than necessary,
+or cause the query provider (e.g. EF Core) to evaluate the projection client-side instead of translating it to SQL.
+
+Starting with v5.0, the default severity of `RMG068` has been raised from info to warning to make these
+potentially expensive situations more visible.
+
+To restore the previous behavior, set the severity back to info in an `.editorconfig` file:
+
+```editorconfig
+dotnet_diagnostic.RMG068.severity = suggestion
+```
diff --git a/src/Riok.Mapperly/AnalyzerReleases.Shipped.md b/src/Riok.Mapperly/AnalyzerReleases.Shipped.md
index bf07bde190..ebb5ca4e57 100644
--- a/src/Riok.Mapperly/AnalyzerReleases.Shipped.md
+++ b/src/Riok.Mapperly/AnalyzerReleases.Shipped.md
@@ -225,3 +225,9 @@ RMG096 | Mapper | Hidden | A MapperIgnore* attribute does not specify a justific
 RMG097 | Mapper | Error   | MapValue Use method parameters cannot be satisfied
 RMG098 | Mapper | Error   | Named mapping additional parameters cannot be satisfied
 RMG099 | Mapper | Error   | Duplicate additional parameter names differing only in casing
+
+### Changed Rules
+
+Rule ID | New Category | New Severity | Old Category | Old Severity | Notes
+--------|--------------|--------------|--------------|--------------|--------------------
+RMG068  | Mapper       | Warning      | Mapper       | Info         | Cannot inline user implemented queryable expression mapping
diff --git a/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs b/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs
index b59eb3232d..60ebaee2dc 100644
--- a/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs
+++ b/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs
@@ -561,7 +561,7 @@ public static class DiagnosticDescriptors
         "Cannot inline user implemented queryable expression mapping",
         "Cannot inline user implemented queryable expression mapping",
         DiagnosticCategories.Mapper,
-        DiagnosticSeverity.Info,
+        DiagnosticSeverity.Warning,
         true
     );
 


Test patch:
diff --git a/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionUserImplementedTest.ClassToClassNonInlinedMethod.verified.txt b/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionUserImplementedTest.ClassToClassNonInlinedMethod.verified.txt
index da49383824..a38a0d7995 100644
--- a/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionUserImplementedTest.ClassToClassNonInlinedMethod.verified.txt
+++ b/test/Riok.Mapperly.Tests/_snapshots/QueryableProjectionUserImplementedTest.ClassToClassNonInlinedMethod.verified.txt
@@ -9,14 +9,14 @@
 */
  : (11,4)-(11,84),
       Message: Cannot inline user implemented queryable expression mapping,
-      Severity: Info,
+      Severity: Warning,
       WarningLevel: 1,
       Descriptor: {
         Id: RMG068,
         Title: Cannot inline user implemented queryable expression mapping,
         MessageFormat: Cannot inline user implemented queryable expression mapping,
         Category: Mapper,
-        DefaultSeverity: Info,
+        DefaultSeverity: Warning,
         IsEnabledByDefault: true
       }
     }