跟踪和预测
- 即使查询的结果类型不是实体类型,如果结果
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 }); }