锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / C#开源英语 / ADO.NET实体框架完善和基本多层技术实例翻译
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

中文译文

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 deletefunctions. You can use this example with stored procedures or without this. This sample is aimed at newcomers to EF.
This is a small idea that occurred to me to implement the concepts of Entity Framework in ASP.NET, but I'm honest I stumbled across a lot of blocks while making this exercise. 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.


three layers
The layer of business contains two projects that are Solution.Bussines.Entities. This contains the same structure of the tables and is mapped with the structure of the database.
The Model has the same structure of database which uses ADO.NET Entity Data Model.
Model
The table customer has a relation with stored procedures.
table
It is important that you see the relation for delCustomer, you only need Id for delete but the entity framework is required for the table referenced.
The next class Customers extends the model generated with ADO.NET Entity Data Model which usesCategoryReference for loading Category of Customer in the line:

this.CategoryReference.Load();
his form easily obtains a class referenced in another class and can also be used for showing in a grid.
public partial class Customers
{
public const string EntitySetName = "Customers";
[Browsable(false)]
public string CategoryName
{
get 
{
string res = "";
if (this.Category != null)
{ 
res = this.Category.Name; 
}
else if (this.CategoryReference != null)
{
this.CategoryReference.Load();
if (this.Category != null)
{ 
res = this.Category.Name; 
}
}
return res;
}
set 
{
this.CategoryReference.EntityKey =
new EntityKey("CustomersEntities.Category", "CategoryId", value);
}
}             

In the next fragment of code was extended the class entities or best call context for that has a singleton pattern and solution to the problem of creating many instances that do not close completely when you use using or dispose.

public static CustomersEntities Context
{
get 
{
string objectContextKey = HttpContext.Current.GetHashCode().ToString("x");
if (!HttpContext.Current.Items.Contains(objectContextKey))
{
HttpContext.Current.Items.Add(objectContextKey, new CustomersEntities());
}
return HttpContext.Current.Items[objectContextKey] as CustomersEntities;
}
}      

Business Layer

The Solution.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.

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内