Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add limitations #2484

Merged
merged 2 commits into from
Jul 9, 2020
Merged

doc: add limitations #2484

merged 2 commits into from
Jul 9, 2020

Conversation

shahabganji
Copy link
Contributor

Describe the limitation of Shadow Properties in the very first paragraph

Describe the limitation of Shadow Properties in the very first pragraph
@ajcvickers
Copy link
Member

@shahabganji This change seems somewhat confusing to me since it implies that the CLR type has properties but they are not being set. Can you explain a bit more what limitation you are trying to convey?

@shahabganji
Copy link
Contributor Author

@ajcvickers , I wanted to convey the difference between the following two queries:

  1. With AsNoTracking()
 var authors = context.Authors.Select(x => x).AsNoTracking();

foreach (var author in authors)
{
    Console.WriteLine(
        $"The entity for AuthorId: {author.Id} " +
        $"was created at: {context.Entry(author).Property("CreatedOn").CurrentValue}");
}
  1. Without AsNoTracking()
var authors2 = context.Authors.Select(x => x);
foreach (var author2 in authors2)
{
    Console.WriteLine(
        $"The entity for AuthorId: {author2.Id} " +
        $"was created at: {context.Entry(author2).Property("CreatedOn").CurrentValue}");
}

And the output will respectively be :

The entity for AuthorId: a2ab54b2-c72c-4644-8bf4-4fa48d3ee89d was created at: 01/01/0001 00:00:00 +00:00
The entity for AuthorId: a2ab54b2-c72c-4644-8bf4-4fa48d3ee89d was created at: 06/27/2020 16:31:47 +00:00

And for clarity, the CreatedOn is a Shadow Property and the Author class is like this:

public class Author
{
     public Guid Id { get; private set; }
     public string FirstName { get; private set; }
     public string LastName { get; private set; }
     public DateTime DateOfBirth { get; private set; }
}

@shahabganji
Copy link
Contributor Author

I could also add a section with an example if you think that will provide a better understanding of the problem

@ajcvickers
Copy link
Member

@shahabganji May add a sentence to Accessing shadow properties. Something like, "Shadow properties cannot be accessed after a no-tracking query since the entities returned are not tracked by the change tracker."

Added a sentence indicating that shadow properties cannot be accessed if the entity returned as no-tracking
@shahabganji
Copy link
Contributor Author

@ajcvickers, The changes applied.

@ajcvickers ajcvickers merged commit 64fbfd2 into dotnet:master Jul 9, 2020
@ajcvickers
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants