Generated Data Layer
Listed below are quick descriptions of the Data Layer class files (generated in the Class Library Project) AspCoreGen 3.0 MVC generates that makes up the
Data Tier. In a 3-tier infrastructure, data layer code is called by the middle layer code. It contains
calls to the database (stored procedures/Ad-Hoc SQL/linq-to-entities using Entity Framework Core).
One of each of the following objects listed below is generated per table in your database.
Generated Class (.cs) |
Quick Description (DataLayer Folder) |
1. Data Layer Base Class
- Sample Code
|
A class file containing methods communicating with the database. The methods encapsulates calls to stored procedures using linq-to-entities queries. Used as a base class. |
2. Data Layer Class
- Sample Code
|
A class file derived from the data layer base class. Additional methods may be added here. |
Generated Entities (.cs) |
Quick Description (EF Folder) |
1. Entity Framework Entities
- Sample Code
|
A class file containing entity properties. |
Generated Ad-Hoc SQL (.cs) |
Quick Description (SQL Folder) |
1. Ad-Hoc SQL Scripts
- Sample Code
|
A class file containing SQL Scripts. |
Note: When generating code you can choose whether to generate Linq-to-Entities queries (EF Core), or Stored Procedures, or
Ad-Hoc SQL. Stored procedures are generated directly in your Microsoft SQL Server. Linq-to-Entities queries (EF Core) or Ad-Hoc SQL are generated
in this Class Library Project.
Accessing Code From the Middle Tier
To make it really simple, the Data Layer method signatures are very similar to the Middle Layer method signatures, we simply add a string constant "DataLayer" to the middle layer method
name to call data layer objects. For example if the middle tier object name is Categories, then the respective data tier object name is CategoriesDataLayer. To call a data layer
method you simply add a dot and then the method name; e.g. CategoriesLayer.TheMethodName();
Select Everything
// we generally don't assign to a variable
var allCategories = CategoriesLayer.SelectAll();
// instead, we simply return the collection to the calling middle tier method
return CategoriesLayer.SelectAll();
Accessing the Database from the Data Layer
As mentioned above, the database can now be accessed using either of the following:
1. Using Linq-To-Entities (Entity Framework Core)
2. Using Stored Procedures
3. Using Ad-Hoc SQL