Skip to content

Commit 638bdfc

Browse files
committed
Update VerifyEntityFramework.cs
1 parent 9a17106 commit 638bdfc

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/Verify.EntityFramework/VerifyEntityFramework.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ static ConversionResult QueryableToSql(object arg, IReadOnlyDictionary<string, o
155155
return new(result, [new("sql", sql)]);
156156
}
157157

158+
internal static bool ShouldFormatSql(this IQueryable queryable)
159+
{
160+
var model = FindModel(queryable.Expression);
161+
return model != null && model.IsSqlServer();
162+
}
163+
164+
static IModel? FindModel(Expression? expression) =>
165+
expression switch
166+
{
167+
EntityQueryRootExpression root => root.EntityType.Model,
168+
MethodCallExpression { Arguments.Count: > 0 } method => FindModel(method.Arguments[0]),
169+
_ => null
170+
};
171+
158172
#pragma warning disable EF9002
159173
public static DbContextOptionsBuilder<TContext> UseDescriptiveTableAliases<TContext>(this DbContextOptionsBuilder<TContext> builder)
160174
where TContext : DbContext =>

0 commit comments

Comments
 (0)