private void Init(bool isNew) { this.keyIsAssigned = this.GetEntityMetadata().GetKeyProperties().All(x => !Equals(x.Property.Get(this), x.Property.Type.DefaultOf())); if (isNew) { MarkNew(); } else { if (!this.keyIsAssigned) { throw new InvalidOperationException($"Entity of type {this.GetType().Name} cannot be marked as existing when all of the key property values are default"); } MarkExisting(); } ChangeTracker.BeginTrackingDeep(); }