From ecb6a0586f5e48a1d0264bd5c6adfad2bc3c70ec Mon Sep 17 00:00:00 2001 From: Saeed Ganji Date: Sat, 27 Jun 2020 20:18:40 +0430 Subject: [PATCH 1/2] doc: add limitations Describe the limitation of Shadow Properties in the very first pragraph --- entity-framework/core/modeling/shadow-properties.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-framework/core/modeling/shadow-properties.md b/entity-framework/core/modeling/shadow-properties.md index d040e505f0..ebcfd7cad3 100644 --- a/entity-framework/core/modeling/shadow-properties.md +++ b/entity-framework/core/modeling/shadow-properties.md @@ -7,7 +7,7 @@ uid: core/modeling/shadow-properties --- # Shadow Properties -Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker. Shadow properties are useful when there is data in the database that should not be exposed on the mapped entity types. +Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker, this means if the entities loaded outside of the change tracker or with `AsNoTracking`, these properties will not have the corresponding values. Shadow properties are useful when there is data in the database that should not be exposed on the mapped entity types. ## Foreign key shadow properties From 5c61b3cf4bf737ac50bea9990b28fb6a5cfb3f0d Mon Sep 17 00:00:00 2001 From: Saeed Ganji Date: Tue, 7 Jul 2020 08:22:05 +0430 Subject: [PATCH 2/2] docs: update the accessing shadow properties section Added a sentence indicating that shadow properties cannot be accessed if the entity returned as no-tracking --- entity-framework/core/modeling/shadow-properties.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entity-framework/core/modeling/shadow-properties.md b/entity-framework/core/modeling/shadow-properties.md index ebcfd7cad3..58698ace06 100644 --- a/entity-framework/core/modeling/shadow-properties.md +++ b/entity-framework/core/modeling/shadow-properties.md @@ -7,7 +7,7 @@ uid: core/modeling/shadow-properties --- # Shadow Properties -Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker, this means if the entities loaded outside of the change tracker or with `AsNoTracking`, these properties will not have the corresponding values. Shadow properties are useful when there is data in the database that should not be exposed on the mapped entity types. +Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker. Shadow properties are useful when there is data in the database that should not be exposed on the mapped entity types. ## Foreign key shadow properties @@ -41,3 +41,5 @@ Shadow properties can be referenced in LINQ queries via the `EF.Property` static var blogs = context.Blogs .OrderBy(b => EF.Property(b, "LastUpdated")); ``` + +Shadow properties cannot be accessed after a no-tracking query since the entities returned are not tracked by the change tracker.