Questions on PlanetaryDocs Sample Application

Siegfried Heintze 1,791 Reputation points

I've been studying DocsContext.cs(line 158) and Jeremy's Blog Post on the sample Planetary Docs.

  1. Why is an ETag defined for docModel (class Document), TagModel & AuthorModel but not DocumentAudit?
  2. Why is the property function called with a value of "PartitionKey" for docModel, tagModel and authorModel? Does it have anything to do with the Etag? Where is the documentation for this property function overload that only accepts a single string?.
  3. Now regarding Jeremy's blog dated May 16 2021 where he says "This is a workaround for the fact that EF Core doesn't handle collections of primitive types" and I see in this sample code that it does.. Well maybe I can answer this question myself: Looks like Jeremy's blog needs to be updated?
  4. Why does the tagModel and the authorModel have a constant partition key of "PartitionKey". This makes no sense.
  5. Now when single stepping with the debugger at DocumentService.cs (line 174) in function SearchTagsAsynch Jeremy is calling a function ComputePartitionKey which returns partitionKey of "Tag" which is the name of the class. Why are we specifying a different partition key? I thought partition keys were ideally a unique itemed field that was specified inside OnModelCreating insdie the Context class. Why are we specifying a partition key again? Why is it constant (again)? Why are we specifying any partitionkey at all for a query? It looks to me like we have the same mystery logic for SearchAuthorsAsync. I see in the documentation for WithPartitionKey that this is "required when using a resource token that provides permission based on a partition key for authentication". Is Jeremy using a resource token for authentication? If so, please point me to this resource token in the source because I have not found it. Might a resource token be a JWT from AAD?
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
678 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 52,831 Reputation points
    1. ETags are for consistency checks for documentations that get updated. The audit documents are insert, and read only no updates.
    2. With Cosmos db for performance every query should include the partition key if possible. This means picking a key that most queries would know about. This is easy with the audit collection.


    1. This is a standard trick for creating a constant, where the name of the constant matches it’s value.

    private const string Meta = nameof(Meta);

    Instead of

    private const string Meta = “Meta”;

    1. The partition key column was named “PartitionKey”, and because it’s value can be generated from the model data, it is not included in the model as a property.