Skip to content

ordepdev/repository-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

repository-pattern

==================

Why?

Extending IEntity

public partial class Foo : Entity
{
    public string Name
    {
        get;
        set;
    }
}

Extending IRepository

public static class FooRepository
{
    public static DL.Foo GetByFooName(this IRepository<DL.Foo> repository, string foo)
    {
        if (string.IsNullOrEmpty(foo))
            return null;
        return repository.FirstOrDefault(x => x.Name == foo);
    }
}

Usage

New instance of UnitOfWork
UnitOfWork uow = new UnitOfWork();
Create
uow.Repository<DL.Foo>().Add(new Foo() { Name = "foo" });
Find one
var foo = uow.Repository<DL.Foo>().FirstOrDefault(x => x.Name = "foo" );
Update
foo.Name = "bar";
uow.Repository<DL.Foo>().Update(foo);
Remove
uow.Repository<DL.Foo>().Remove(foo);
Find several records
var results = uow.Repository<DL.Foo>().Where(x => x.CreatedDate < DateTime.Now);
Save Changes
uow.Commit();

About

my approach to build a repository pattern with EF and C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages