Giter Site home page Giter Site logo

Comments (8)

codelovercc avatar codelovercc commented on May 25, 2024

We can support AsTracking like this:

In static class SpecificationBuilderExtensions , add two methods

    /// <summary>
    /// If the entity instances are modified, this will be detected
    /// by the change tracker.
    /// </summary>
    /// <param name="specificationBuilder"></param>
    public static ISpecificationBuilder<T> AsTracking<T>(
        this ISpecificationBuilder<T> specificationBuilder) where T : class
        => AsTracking(specificationBuilder, true);

    /// <summary>
    /// If the entity instances are modified, this will be detected
    /// by the change tracker.
    /// </summary>
    /// <param name="specificationBuilder"></param>
    /// <param name="condition">If false, the setting will be discarded.</param>
    public static ISpecificationBuilder<T> AsTracking<T>(
        this ISpecificationBuilder<T> specificationBuilder,
        bool condition) where T : class
    {
      if (condition)
      {
        specificationBuilder.Specification.AsNoTracking = false;
      }

      return specificationBuilder;
    }

In class AsNoTrackingEvaluator, modify GetQuery<T> method.

    public IQueryable<T> GetQuery<T>(IQueryable<T> query, ISpecification<T> specification) where T : class
    {
      return specification.AsNoTracking ?  query.AsNoTracking() : query.AsTracking();
    }

from specification.

codelovercc avatar codelovercc commented on May 25, 2024

In situation one, We can let the repository class control the query is tracked or not and ignore specification's AsNoTracking.

protected virtual IQueryable<TEntity> ApplySpecification(ISpecification<TEntity> specification,
        bool isTracked = true,
        bool evaluateCriteriaOnly = false) where TEntity : class
    {
        var q = SpecificationEvaluator.GetQuery(EntitySet, specification, evaluateCriteriaOnly);
        return isTracked ? q.AsTracking() : q.AsNoTracking();
    }

So, What do we say? I still think that support AsTracking will be nicer :)

from specification.

ardalis avatar ardalis commented on May 25, 2024

@fiseni thoughts?

from specification.

fiseni avatar fiseni commented on May 25, 2024

I think we had another request for AsTracking, so let's add it. @codelovercc Do you want to create a PR?

from specification.

codelovercc avatar codelovercc commented on May 25, 2024

Sure, I'd like to.

from specification.

codelovercc avatar codelovercc commented on May 25, 2024

Should we rename class AsNoTrackingEvaluator to TrackingEvaluator? When it support AsTracking and AsNoTracking, this may be more suitable but it's a breaking change.

from specification.

fiseni avatar fiseni commented on May 25, 2024

No, no need for that. You'll create a separate new file called AsTrackingEvaluator.

from specification.

codelovercc avatar codelovercc commented on May 25, 2024

Completed, PR #338

from specification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.