跟蹤和預測
- 即使查詢的結果型別不是實體型別,如果結果
contains entity
型別仍然是tracked by default
示例:
-
在以下查詢中,返回
anonymous type
,結果集will be tracked
中的Book
例項using (var context = new BookContext()) { var book = context.Books.Select(b => new { Book = b, Authors = b.Authors.Count() }); }
-
如果結果集
does not
包含任何entity
型別,則執行no tracking
示例:
-
在以下查詢中,返回帶有來自實體的某些值的
anonymous type
(但實際entity
型別的no instances
),沒有執行跟蹤。using (var context = new BookContext()) { var book = context.Books.Select(b => new { Id = b.BookId, PublishedDate = b.Date }); }