Skip to content

Instantly share code, notes, and snippets.

@0x414c49
Created September 7, 2020 11:07
Show Gist options
  • Save 0x414c49/16e22720162bd6b1b437372080970ca6 to your computer and use it in GitHub Desktop.
Save 0x414c49/16e22720162bd6b1b437372080970ca6 to your computer and use it in GitHub Desktop.
EF Core - Tag Queries with source information
public static class DbContextExtensions
{
public static IQueryable<T> TagWithSource<T>(this IQueryable<T> queryable,
string tag = "",
[CallerMemberName] string methodName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int line = 0)
{
return queryable.TagWith(string.IsNullOrEmpty(tag)
? $"{methodName} - {sourceFilePath}:{line}"
: $"{tag}{Environment.NewLine}{methodName} - {sourceFilePath}:{line}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment