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

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

Open
rahulrai-in opened this issue Oct 24, 2018 · 5 comments
Open

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

rahulrai-in opened this issue Oct 24, 2018 · 5 comments
Assignees

Comments

@rahulrai-in
Copy link

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?

@mfidemraizer
Copy link
Owner

mfidemraizer commented Oct 24, 2018

Hey! Thank you for using TrackerDog.

I see.

The issue here is that there's no public interface to tackle this problem at the moment.

See this:

public object CreateForCollection(object some, IChangeTrackableObject parentObject, PropertyInfo parentObjectProperty)

...which isn't part of any public interface.

So, you want to build the whole tracked list this way, right?

this.TrackedEntities = objectFactory.CreateOf<List<T>>();

Am I on the right track?

@rahulrai-in
Copy link
Author

Yes. That would make my class very similar to EF DbContext, which has trackable DbSet classes.

@mfidemraizer
Copy link
Owner

Anyway, would be really disturbing that you might design a class with just that property for a while?

When I tried to provide a solution to other issues, I've found myself stuck, because my VM with Windows 10 and VS2017 is broken, and now my main OS is Linux since a year.

I believe that the best I can do is to provide just the .NET Standard Library distribution, and deprecate the Full Framework-specific one, so I may be able to provide solutions and releases sooner...

If this is really disturbing, I can implement the solution and publish the new .NET Standard Library NuGet package version with your requested feature, and later the other one for the Full Framework.

Are you on .NET Core?

@rahulrai-in
Copy link
Author

rahulrai-in commented Oct 24, 2018

Thanks for the prompt reply and taking action on the issue so early. I am using .net core and don't need a full framework solution. If you want, I can submit a PR if you let me know what needs to be done. I can validate the solution on my windows machine as well. Thanks.

@mfidemraizer
Copy link
Owner

The PR would be really wonderful, but I guess you'll have a good headache.

While that unpublished method is a good approximation to what you need, we need a new one which may not require a parent object (an owner) of the whole collection but just the collection type or an existing collection instance.

It should be an easy one, but I'm not sure if you would be able to handle it without understanding how it works (it's not as easy as publishing the method).

I'll try to solve this tonight or tomorrow and I'll give you some output about what I've achieved in that moment.

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

No branches or pull requests

2 participants