Simple Sample with Entity Framework
Introduction
This sample shows how you can use the entity framework in an application ASP.NET with an architecture in layers. This is useful for applications that are pretty small and fast. The code uses
select
, update
, create
and delete
functions. You can use this example with stored procedures or without this. This sample is aimed at newcomers to EF.The first context is complex and that creates some objects in memory, on the other hand I had to send objects to be processed. There was no need for stored entity framework to be a key, otherwise errors would be raised.
Database
First view the structure of the database. This example uses two tables, i.e.,Customers
and Category
.Customers
have a relation with Category
.Project
The project has a structure in three layers. The layer for business that contains the project entities, the project components, the layer of data and the layer of presentation.Business Layer
TheSolution.Bussines.Components
layer manages the logic of business and joins the layer of data with the layer of entities.This layer is composed by the class CustomersComponent.cs which calls the layer of data. Here you can add more logic code for your business.
Data Layer
The data layer contains the logic for accessing the database.Insert a new record in the database. This method uses the customer created previously for adding to context and saving the changes in the database.
Presentation Layer
In the presentation layer built in ASP.NET, we have the form for update or add records, the principal method sends to the layer components the action for that to execute in the database. This first fills the objectcustomer
with the form information and the next calls Update or Add.
No comments:
Post a Comment