Skip to content

Commit cab1a47

Browse files
Copilotroji
andauthored
Document TagWithCallSite method in Query Tags documentation (#5215)
Co-authored-by: roji <1862641+roji@users.noreply.github.com>
1 parent ecec281 commit cab1a47

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • entity-framework/core/querying

entity-framework/core/querying/tags.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ FROM [People] AS [p]
6868
ORDER BY [p].[Location].STDistance(@__myLocation_0) DESC
6969
```
7070

71+
## Tagging with file name and line number
72+
73+
Queries can be automatically tagged with the file name and line number where the LINQ query is defined in source code. This is done using the <xref:Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.TagWithCallSite*> method:
74+
75+
```csharp
76+
var myLocation = new Point(1, 2);
77+
var closestPeople = await (from f in context.People.TagWithCallSite()
78+
orderby f.Location.Distance(myLocation) descending
79+
select f).Take(5).ToListAsync();
80+
```
81+
82+
This query translates to (the actual line number will reflect where the query is defined in the source file):
83+
84+
```sql
85+
-- file: C:\Work\EntityFramework.Docs\samples\Program.cs:23
86+
87+
SELECT TOP(@__p_1) [p].[Id], [p].[Location]
88+
FROM [People] AS [p]
89+
ORDER BY [p].[Location].STDistance(@__myLocation_0) DESC
90+
```
91+
7192
## Known limitations
7293

7394
**Query tags aren't parameterizable:**

0 commit comments

Comments
 (0)