I want to save the history of all changes made to my Comment
entity / table.
My approach:
- use an "insert only" table
- use a composite PK, made of a db-generated int key and a db-generated DateTime stamp
- use AsNoTracking on the entities
But, suppose it's a navigation property of this entity:
public Article {
public int ID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public virtual Comment Comments { get; set; }
}
So if I call articleFoo.Comments
it will get all entities which means all revisions. I only want to get the "latest" one. How would I achieve this?
---UPDATE---
- If I use Linq filtering then how would I go about it, or
if I use the sprocs option then how would I do that? - my assumptions are incomplete- I must generate the composite key because for two revision entities, their ID must equal but their updated datetime must differ. So I can't let the db generate those automtically, or can I?