Skip to content

Commit

Permalink
Doc updated for wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanvir Ahmad Arjel authored Jun 10, 2021
1 parent b5c5581 commit 27ccfed
Showing 1 changed file with 7 additions and 212 deletions.
219 changes: 7 additions & 212 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This library is a Generic Repository implementation for EF Core ORM which will remove developers' pain to write repository layer for each .NET Core and .NET project.

## ⭐ Giving a star
## ⭐ Giving a star

**If you find this library useful, please don't forget to encouraging me to do such more stuffs by giving a star to this repository. Thank you.**

## 🔥 What's new 🔥
## 🔥 What's new

### Pagination Support:
```C#
Expand All @@ -32,7 +32,7 @@ List<EmployeeDto> items = await _repository.GetFromRawSqlAsync<EmployeeDto>(sqlQ

```

## ⚙️ This library includes following notable features: ⚙️
## ⚙️ This library includes following notable features:

1. This library can be run on any .NET Core or .NET application which has .NET Core 3.1, .NET Standard 2.1 and .NET 5.0 support.

Expand All @@ -56,7 +56,7 @@ List<EmployeeDto> items = await _repository.GetFromRawSqlAsync<EmployeeDto>(sqlQ

13. Free raw SQL query support both for complex type and primitive types.

## ✈️ How do I get started? ✈️
## ✈️ How do I get started?

First install the latest version of `TanvirArjel.EFCore.GenericRepository` [nuget](https://www.nuget.org/packages/TanvirArjel.EFCore.GenericRepository) package into your project as follows:

Expand All @@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
}
```

## 🛠️ Usage: Query 🛠️
## 🛠️ Usage: Query

```C#
public class EmployeeService
Expand All @@ -100,7 +100,7 @@ public class EmployeeService
}
}
```
## 🛠️ Usage: Command 🛠️
## 🛠️ Usage: Command

```C#
public class EmployeeService
Expand Down Expand Up @@ -150,209 +150,4 @@ public class EmployeeService
}
```

## 🕮 More Details: 🕮

#### 1. To get all the data:

```C#
var employeeList = await _repository.GetListAsync<Employee>();

var noTrackedEmployeeList = await _repository.GetListAsync<Employee>(asNoTracking: true);
````

#### 2. To get a filtered list of data:

```C#
var employeeList = await _repository.GetListAsync<Employee>(e => e.EmployeeName.Contains("Tanvir") && e.DepartmentName == "Software");

var noTrackedEmployeeList = await _repository
.GetListAsync<Employee>(e => e.EmployeeName.Contains("Tanvir") && e.DepartmentName == "Software", asNoTracking: true);
```

#### 3. To get a list of data by Specification<T>:

```C#
Specification<Employee> specification = new Specification<Employee>();
specification.Conditions.Add(e => e.EmployeeName.Contains("Tanvir"));
specification.Includes = ep => ep.Include(e => e.Department);
specification.OrderBy = sp => sp.OrderBy(e => e.EmployeeName).ThenBy(e => e.DepartmentName);
specification.Skip = 0;
specification.Take = 10;

List<Employee> employeeList = await _repository.GetListAsync<Employee>(specification);

List<Employee> noTrackedEmployeeList = await _repository.GetListAsync<Employee>(specification, true);
```

#### 4. To get the projected entity list:

```C#
Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var projectedList = await _repository.GetProjectedListAsync<Employee, object>(selectExpression);
```

#### 5. To get filtered projected entity list:

```C#
Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var filteredProjectedList = await _repository.GetProjectedListAsync<Employee, object>(e => e.IsActive, selectExpression);
```

#### 6. To get the projected entity list by `Specification<T>`:

```C#
Specification<Employee> specification = new Specification<Employee>();
specification.Conditions.Add(e => e.EmployeeName.Contains("Tanvir"));
specification.Includes = ep => ep.Include(e => e.Department);
specification.OrderBy = sp => sp.OrderBy(e => e.EmployeeName).ThenBy(e => e.DepartmentName);
specification.Skip = 0;
specification.Take = 10;

Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var projectedList = await _repository.GetProjectedListAsync<Employee, object>(specification, selectExpression);
```

#### 7. To get an entity by Id (primary key):

```C#
Employee employee = await _repository.GetByIdAsync<Employee>(1);

Employee noTrackedEmployee = await _repository.GetByIdAsync<Employee>(1, true);
```

#### 8. To get a projected entity by Id (primary key):

```C#
Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var projectedEntity = await _repository.GetProjectedByIdAsync<Employee, object>(1, selectExpression);
```

#### 9. To get a single entity by any condition/filter:

```C#
Employee employee = await _repository.GetAsync<Employee>(e => e.EmployeeName == "Tanvir");

Employee noTrackedEmployee = await _repository.GetAsync<Employee>(e => e.EmployeeName == "Tanvir", true);
```

#### 10. To get a single entity by `Specification<T>`:

```C#
Specification<Employee> specification = new Specification<Employee>();
specification.Conditions.Add(e => e.EmployeeName == "Tanvir");
specification.Includes = sp => sp.Include(e => e.Department);
specification.OrderBy = sp => sp.OrderBy(e => e.Salary);

Employee employee = await _repository.GetAsync<Employee>(specification);

Employee noTrackedEmployee = await _repository.GetAsync<Employee>(specification, true);
```

#### 11. To get a single projected entity by any condition/filter:

```C#
Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var projectedEntity = await _repository.GetProjectedAsync<Employee, object>(e => e.EmployeeName == "Tanvir", selectExpression);
```

#### 12. To get a single projected entity by `Specification<T>`:

```C#
Specification<Employee> specification = new Specification<Employee>();
specification.Conditions.Add(e => e.EmployeeName == "Tanvir");
specification.Includes = sp => sp.Include(e => e.Department);
specification.OrderBy = sp => sp.OrderBy(e => e.Salary);

Expression<Func<Employee, object>> selectExpression = e => new { e.EmployeeId, e.EmployeeName };
var projectedEntity = await _repository.GetProjectedAsync<Employee, object>(specification, selectExpression);
```

#### 13. To check if an entity exists:

```C#
bool isExists = await _repository.ExistsAsync<Employee>(e => e.EmployeeName == "Tanvir");
```

#### 14. To create or insert a new entity:

```C#
Employee employeeToBeCreated = new Employee()
{
EmployeeName = "Tanvir",
..........
}

await _repository.InsertAsync<Employee>(employeeToBeCreated);
```

#### 15. To create or insert a collection of new entities:

```C#
List<Employee> employeesToBeCreated = new List<Employee>()
{
new Employee(){},
new Employee(){},
}

await _repository.InsertAsync<Employee>(employeesToBeCreated);
```

#### 16. To update or modify an entity:

```C#
Employee employeeToBeUpdated = new Employee()
{
EmployeeId = 1,
EmployeeName = "Tanvir",
..........
}

await _repository.UpdateAsync<Employee>(employeeToBeUpdated);
```

#### 17. To update or modify the collection of entities:

```C#
List<Employee> employeesToBeUpdated = new List<Employee>()
{
new Employee(){},
new Employee(){},
}

await _repository.UpdateAsync<Employee>(employeesToBeUpdated);
```

#### 18. To delete an entity:

```C#
Employee employeeToBeDeleted = new Employee()
{
EmployeeId = 1,
EmployeeName = "Tanvir",
..........
}

await _repository.DeleteAsync<Employee>(employeeToBeDeleted);
```

#### 19. To delete a collection of entities:

```C#
List<Employee> employeesToBeDeleted = new List<Employee>()
{
new Employee(){},
new Employee(){},
}

await _repository.DeleteAsync<Employee>(employeesToBeDeleted);
```

#### 20. To get the count of entities with or without condition:

```C#
int count = await _repository.GetCountAsync<Employee>(); // Count of all
int count = await _repository.GetCountAsync<Employee>(e => e.EmployeeName = "Tanvir"); // Count with specified condtion
long longCount = await _repository.GetLongCountAsync<Employee>(); // Long count of all
long longCount = await _repository.GetLongCountAsync<Employee>(e => e.EmployeeName = "Tanvir"); // Long count with specified condtion
```
### For more detail documentaion, please visit [Documentation Wiki](https://github.com/TanvirArjel/EFCore.GenericRepository/wiki)

0 comments on commit 27ccfed

Please sign in to comment.