Skip to content

How to track just the list inside a class? #49

@rahulrai-in

Description

@rahulrai-in

I am creating a custom DbContext class which requires a List of entities that I want to track. I want to attach tracker only to the list but the samples in documentation say that the tracker needs to be configured for the containing class as well. Here is how my code looks at the moment, which is not ideal.

    public class CustomDbContextBase<T> : IUnitOfWork where T : Entity
    {
        public CustomDbContextBase()
        {
            // no op: Required for change tracking.
        }

        protected CustomDbContextBase(string endpointUrl, string databaseId, string masterKey, string collectionId, IMediator mediator)
        {
             // Initialize change tracking
            var config = ObjectChangeTracking.CreateConfiguration();
            config.TrackThisType<CustomDbContextBase<T>>(t => t.IncludeProperty(a => a.TrackedEntities));
            var objectFactory = config.CreateTrackableObjectFactory();
            this.TrackedEntities = objectFactory.CreateOf<CustomDbContextBase<T>>().TrackedEntities;
        }

        public virtual IList<T> TrackedEntities { get; set; }
...
    }

How can I attach tracker to just the TrackedEntities list and not the CustomDbContextBase?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions