Git Product home page Git Product logo

ffernandolima / ef-core-data-access Goto Github PK

View Code? Open in Web Editor NEW
157.0 157.0 24.0 2.16 MB

It's a modern and generic data access structure for .NET and Microsoft.EntityFrameworkCore. It supports UnitOfWork, Repository and QueryBuilder patterns. It also includes auto history utilities, multiple databases support with distributed transactions and databases/tables sharding for some database providers.

License: MIT License

ef-core-data-access's Introduction

ef-core-data-access's People

Contributors

ffernandolima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ef-core-data-access's Issues

[Feature Request] ```Task<T> UpdateAsync()``` method

Example:

...
public void UpdateBlog()
{
    var repository = _unitOfWork.Repository<Blog>();

    var blog = await repository.UpdateAsync(model); ///Not work
    
    _unitOfWork.SaveChangesAsync();
}
...

Look like IAsyncRepository<T> in EntityFrameworkCore.Repository.Interfaces doesn't have method below:

 Task<T> UpdateAsync(
      T entity, 
      params Expression<Func<T, object>>[] properties
      CancellationToken cancellationToken = default (CancellationToken));

Pool context

Hello.
I really liked your library.

I would like to talk about the outcome. In EF 5 AddPooledDbContextFactory. This allows the pool factory to be used by the context. Is it possible to use it in this library?

Make DbContext in defined UnitOfWork protected

Unit of work is a way to encapsulate db context but i see it is fully public. Some might need to access DbContext but thats why i ask to make it protected so people can just create a simple wrapper around your UnitOfWork to use it but currently forcing public DbContext does not make any sense to me. If there is some other reason that i don't know enlighten me.

Support for ExecutionStrategy (in conjunction with Transactions)

Have you ever considered adding support for ExecutionStrategy in conjunction with transactions? I recently ran across a situation where I wasn't able to use the normal create Transaction because of conflicts with the application's existing retry strategy. After a lot of trial and error, I finally settled on creating a new execution strategy and executing the transaction off it. They have an extension method available that wraps the try/catch begin/commit/rollback so there wasn't much to a barebones version (although there are several more signatures you could support) - this was my down and dirty (and definitely not fully tested) method on the UnitOfWork:

public async Task ExecuteInTransactionAsync(Func<Task> operation, Func<Task<bool>> verifySucceeded = null)
{
    var strategy = _context.Database.CreateExecutionStrategy();

    await strategy.ExecuteInTransactionAsync(
        async () => await operation(),
        () => verifySucceeded != null ? verifySucceeded() : Task.FromResult(true)
    );
}

and then you just call it as needed like:

await _unitOfWork.ExecuteInTransactionAsync(
  async () =>
  {
       ......
       await whatever.SaveChangesAsync();
       await whatever.SaveChangesAsync();
       await whatever.SaveChangesAsync();
       ....
  });

Just thought I'd mention it while it was on my mind.

Thanks-

error when update

when update entity show me below error

The database operation was expected to affect 1 row(s), but actually affected 0 row(s)

update code is

var updatedCourse = _mapper.Map<Model.Course.Course>(request.Course);
var course = repository.Update(updatedCourse);
await unitOfWork.SaveChangesAsync(cancellationToken: cancellationToken);

Include behavior different when using UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)

I've just started trying to implement this library into a project and I'm having trouble getting it to load a one-to-one relationship.

I have a User entity, and I have a Queue entity. There is a single queue/one-to-one for each user, so I have a Queue property on the User entity using the foreign key.

When I attempt to Include the Queue property, unless I have NoTracking set, it isn't populated.

var repository = _unitOfWork.Repository<User>();

var query = repository.SingleResultQuery()
          .AndFilter(u => u.UserId == userId)
          .Include(src => src.Include(u => u.Queue));
          /////.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);

var user = await repository.SingleOrDefaultAsync(query);

user.Queue will be null here...

var query = repository.SingleResultQuery()
          .AndFilter(u => u.UserId == userId)
          .Include(src => src.Include(u => u.Queue));
          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);

var user = await repository.SingleOrDefaultAsync(query);

user.Queue is correctly loaded here....

What am I doing wrong?

Thanks-

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.