ProphetsWay.BaseDataAccess 2.2.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package ProphetsWay.BaseDataAccess --version 2.2.0
NuGet\Install-Package ProphetsWay.BaseDataAccess -Version 2.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProphetsWay.BaseDataAccess" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ProphetsWay.BaseDataAccess --version 2.2.0
#r "nuget: ProphetsWay.BaseDataAccess, 2.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ProphetsWay.BaseDataAccess as a Cake Addin
#addin nuget:?package=ProphetsWay.BaseDataAccess&version=2.2.0

// Install ProphetsWay.BaseDataAccess as a Cake Tool
#tool nuget:?package=ProphetsWay.BaseDataAccess&version=2.2.0

ProphetsWay.BaseDataAccess

Build Status:
Build Status

BaseDataAccess is a light library that is meant to help decouple your software's business logic projects from your Data Access Layer (DAL) implementation. With some new technologies, it is easy to allow yourself to create entity/models in your DAL and use them directly in your business layers, however this makes it difficult to replace your DAL implementation if you decide to change how/what is hosting your data. By adhering to a specific project dedicated to the models and interfaces required for your solution, you aren't restricted to the models that are created for you by your data layer implementation.

Getting Started

BaseDataAccess is a lightweight project that consists of mostly just interfaces, but it also has a base abstract class you can utilize for convenience within your project. This base class does use Reflection to work some magic, and if you're concerned about speed, you can override those virtual methods and manually evaluate them (or not use the base abstract class and just implement the interface on your own).

Prerequisites

You can pull a copy of the source code from GitHub, or you can reference the library from NuGet.org from within Visual Studio.

Install-Package ProphetsWay.BaseDataAccess 
dotnet add package ProphetsWay.BaseDataAccess 

Referencing and Using

The approach to use this project is that you want to create a new project in your solution to specify the data access requirements. Generally my naming convention is "[ProjectName].DataAccess" and then the project that implements the actual data access layer is "[ProjectName].DataAccess.[ImplementationName]". For "ImplementationName" I generally use a shortcut name to identify what the implementation is working with (ex: MSSQL, MySQL, Oracle, SQLite).

[ProjectName].DataAccess

In this project, I recommend the folder layout as follows: root

  • Entities / Models Folder
  • IDaos Folder
  • I[ProjectName]DataAccess Class
Entities/Models

The Entities / Models folder name is really a personal preference on the naming convention. The point is that you define the entities that you will be using in your solution here. Defining them outside of the DAL implementation allows you to use them however you see fit within your application. Any new DAL implementation will have to interact with the models defined here-in. All of your entities must inherit the interface IBaseEntity. This is to flag the entities as compatible with the other interfaces.

IDaos

The IDaos folder is meant to specify what actions you want for each specific entity in your Entities folder. Generally you should name your interfaces I[EntityName]Dao so that it's quick and easy to identify which files reference which entities. Your interface should inherit from one of the base DAO interfaces. Using one of the base interfaces will automatically include specific methods, however this DAO is where you will also specify any additional functionality that you need this entity to have. (ex: IList<Customer> GetCustomersByCompanyId(int companyId); to be specified on the ICustomerDao) All of the base interfaces are generic and require a type T to be specified, here you will specify the type of the entity this DAO is for.

public interface ICustomerDao : IBaseDao<Customer>
IBaseDao

IBaseDao specifies your basic CRUD calls: Get, Insert, Update, and Delete. Each call does require a parameter of the type of entity to be passed to it, even for Get and Delete where you might normally just need the "Id" of the record. This is done on purpose so that all interfaces for all entities have unique method signatures for use in the master interface (discussed in the next section). If you do not like/want this style of functionality, you can skip all three of these BaseDao interfaces completely and manually create all the CRUD calls in each entity IDao (as well as whatever other functionality you need). The only thing to remember is that you must make each method signature unique (so instead of just T Get(T item); you have Customer GetCustomer(int customerId);))

T Get(T item);
void Insert(T item);
int Update(T item);
int Delete(T item);
IBaseGetAllDao

IBaseGetAllDao inherits from IBaseDao, but additionally specifies a GetAll call. This call also requires the parameter similar to the above mentioned situation.

IList<T> GetAll(T item);
IBasePagedDao

IBasePagedDao also inherits from IBaseDao, and additionally specifies a GetCount and GetPaged calls. More of the same with the required parameters, however these functions are used to get the upper boundary of how many of an entity you have, and then getting a particular subset of them; useful for user interface based queries when trying to optimize data being queried and sent to your front end.

IList<T> GetPaged(T item, int skip, int take);
int GetCount(T item);
I[ProjectName]DataAccess

This is the master interface for your DAL implementation. This shouldn't have any methods manually specified in it, this should be an interface of interfaces. In here you'll inherit all the IDao's you created for each of your entities before. In some cases you might have some functionality that doesn't persist to a particular entity and don't feel like it fits in an any entity's DAO, in those cases you would put the method signature here.

[ProjectName].DataAccess.[ImplementationName]

So technically, you can implement your DAL however you want to, so long as your main point of instantiation inherits/implements the IDataAccess interface defined above. Currently my approach has been to create a DAO for each IDao specified, that way it's easier to find things in your source code.
internal class CustomerDao : ICustomerDao will set you up so that all the required CRUD calls and other methods you specified will be added and typed to the correct entity type. I recommend using internal on the specific DAO's as these are separate for the convenience of the developer and separation of logic, but shouldn't be accessible outside of the project, only the class implementing IDataAccess should be created and accessible outside of this project.

Depending on your actual implementation, you might have a bunch of other stuff in this project to support how the DAOs actually interact with the data storage you're using. However the final piece to mention here is the main IDataAccess implementation. Generally I name this class [ProjectName]DataAccess, but it doesn't matter. If you created the separate DAOs for each entity, then in here you will have to instantiate each of those DAOs and just pass thru each method signature/call into each specific DAO.

public class ExampleDataAccess : BaseDataAccess, IExampleDataAccess
{
    private readonly ICustomerDao _customerDao = new CustomerDao();
        
    public Customer Get(Customer item){
        return _customerDao.Get(item);
    }
}

The class BaseDataAccess has some generic methods to execute the CRUD calls. These methods are available to generically call any entity from the DataAccess object without having to explicitly know what type of entity it is (so long as it implements IBaseEntity)

    void Insert<T>(T item) where T : IBaseEntity, new()
    T Get<T>(object id) where T : IBaseEntity, new()
    int Update<T>(T item) where T : IBaseEntity, new()
    int Delete<T>(T item) where T : IBaseEntity, new()

Running the tests

The library has 35 unit tests currently. I tried to cover everything possible; however they are created in an Example project within another repository. https://github.com/ProphetManX/ProphetsWay.Example

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 is compatible.  net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.5.1

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ProphetsWay.BaseDataAccess:

Package Downloads
ProphetsWay.EFTools The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A small library that is useful when utilizing EntityFramework for a Data Access Layer (DAL) while adhering to Business Layer to DAL decoupling. This uses the paradigm explained in https://github.com/ProphetManX/ProphetsWay.BaseDataAccess. See the README for more information. For more information on this project, please go to https://github.com/ProphetManX/ProphetsWay.EFTools.

ProphetsWay.iBatisTools The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A small library that is useful when utilizing iBatisNet for a Data Access Layer (DAL). Go to https://github.com/ProphetManX/ProphetsWay.iBatisTools for more information.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 501 8/16/2022
2.2.0-447.Beta 82 8/16/2022
2.2.0-447.Alpha 340 8/15/2022
2.1.5 744 8/10/2022
2.1.5-431.Beta 91 8/10/2022
2.1.5-431.Alpha 87 8/9/2022
2.1.5-429.Beta 82 8/9/2022
2.1.5-429.Alpha 86 8/9/2022
2.1.5-427.Alpha 89 8/9/2022
2.1.4 430 5/11/2022
2.1.4-416.Beta 468 5/11/2022
2.1.4-416.Alpha 455 5/11/2022
2.1.4-412.Alpha 453 5/11/2022
2.1.4-410.Alpha 463 5/11/2022
2.1.4-409.Alpha 94 5/10/2022
2.1.4-393.Beta 110 5/7/2022
2.1.4-393.Alpha 109 5/7/2022
2.1.4-392.Alpha 108 5/7/2022
2.1.3 405 5/6/2022
2.1.3-385.Beta 101 5/6/2022
2.1.3-385.Alpha 107 5/6/2022
2.1.3-367.Alpha 105 4/28/2022
2.1.2 426 4/28/2022
2.1.2-365.Alpha 104 4/28/2022
2.1.2-363.Beta 105 4/28/2022
2.1.2-363.Alpha 100 4/28/2022
2.1.1-349.Alpha 140 8/26/2021
2.1.1-343.Alpha 130 8/26/2021
2.1.1-293.Alpha 144 8/16/2021
2.1.1-292.Alpha 143 8/16/2021
2.1.0-315.Alpha 125 8/19/2021
2.1.0-307.Alpha 124 8/19/2021
2.1.0-287.Beta 139 2/2/2021
2.1.0-287.Alpha 134 2/1/2021
2.1.0-285.Alpha 141 2/1/2021
2.1.0-283.Beta 145 2/1/2021
2.1.0-283.Alpha 142 2/1/2021
2.1.0-281.Alpha 156 2/1/2021
2.0.0 369 2/1/2021
2.0.0-273.Beta 138 2/1/2021
2.0.0-273.Alpha 143 2/1/2021
2.0.0-267.Beta 207 1/28/2021
2.0.0-267.Alpha 133 1/28/2021
2.0.0-262.Beta 143 1/28/2021
2.0.0-262.Alpha 139 1/28/2021
2.0.0-253.Beta 144 1/28/2021
2.0.0-253.Alpha 188 1/27/2021
1.1.1 726 6/2/2020
1.1.1-171.Beta 274 6/2/2020
1.1.1-171.Alpha 266 6/2/2020
1.1.0 513 5/31/2020
1.1.0-126.Beta 298 5/19/2020
1.1.0-126.Alpha 264 5/19/2020
1.0.0 538 3/24/2019
1.0.0-Beta-69 398 3/24/2019
1.0.0-Beta-65 386 3/23/2019
1.0.0-Alpha-83 410 3/24/2019
1.0.0-Alpha-82 422 3/24/2019
1.0.0-Alpha-69 397 3/24/2019
1.0.0-Alpha-68 402 3/24/2019
1.0.0-Alpha-65 407 3/23/2019
1.0.0-Alpha-64 396 3/23/2019
1.0.0-Alpha-61 397 3/23/2019
0.0.0-Alpha-60 394 3/23/2019

# v2.2.0
### Added Generic CRUD Calls
Added the ability to call ```Insert```, ```Update```, and ```Delete``` generically, similar to how ```Get<\T>(int id)``` works already.