Skip to content

Account for DbContext tracking #9

@soljarka

Description

@soljarka

When I send several queries with similar arguments yet different asOf timestamps using a single instance of DbContext, I always get similar results, apparently because of tracking. I solve this issue in my code by adding AsNoTracking():

        public static IQueryable<TSource> AsOfConditional<TSource>(this IQueryable<TSource> source, DateTime? asOf)
        where TSource : class
        {
            if (asOf.HasValue)
                return source.AsOf(asOf.Value).AsNoTracking();

            return source;
        }

This may be not the responsibility of this library, but it might be helpful to extend AsOf() or at least give users some hints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions