Comments (8)
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.
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.
@fiseni thoughts?
from specification.
I think we had another request for AsTracking
, so let's add it. @codelovercc Do you want to create a PR?
from specification.
Sure, I'd like to.
from specification.
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.
No, no need for that. You'll create a separate new file called AsTrackingEvaluator
.
from specification.
Completed, PR #338
from specification.
Related Issues (20)
- Request to multi-target EntityFramework6.csproj and include net6.0 HOT 3
- Query.Dstinct() HOT 1
- Update LangVersion to C# 10 or 11
- Update conventions and styling
- Update Sample projects
- Remove obsolete API
- Update pipelines.
- Including nullable/optional navigation property causes only non-nullable connected objects to be returned HOT 3
- Unable to apply Take() to a navigation property HOT 5
- Refactor and improve integration test fixtures.
- Why do the Update and Delete not returning anything? HOT 3
- Logging in the Package HOT 4
- Feature Request: Deletion of entities via specification HOT 5
- Shadow properties HOT 4
- Query to return anonymous type HOT 4
- Question: Can I some how join table "B" when my entity T does not have a navigation property to "B" ? HOT 2
- Expression Evaluation HOT 8
- Simplify Cache usage HOT 5
- DbSet<T>.WithSpecification together with ISpecification<T, TDestination> throws SelectorNotFoundException HOT 4
- Conceptual question about the ORM specific implementations HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from specification.