NetTiers学习总结3--实体层
更新时间:2023-11-15 05:46:01 阅读量: 教育文库 文档下载
- NetTiers推荐度:
- 相关推荐
第三次 实体层 Entity Layer
You can think of an Entity as the Reflection of a Database-table exposed in Object Oriented fashion. The Word Entity is the same which is commonly used and mostly for a Database-Table. So in the .Net environment an object reflecting a Database-table cascadingly, Exposing its Columns as class-Properties, Carefully matching the Data Types between a
database-column and a .Net-Type(Let say string for varchar and Int16 for smallint).
Now think of a Database-Table 'USERS' where, definitely, each row of table is representing a single User's complete information(like her ID, Name, Age and Address) and on the other hand in .Net imagine an Object 'User' (with properties ID, Name, Age and Address). It actually is representing One User from database-table 'Users' or One Row of database-table.
.netTiers' architecture provides us an environment where we can Control the database entities by passing in these .Net entities in special methods. In fact those special methods which Control these .Net entities are called Controller Objects. We'll be studying about them in next articles. for now we should make sure that we know that we can call some dedicated methods from Controller objects to Retrieve an Entity or List of Entities. We can pass in an Entity into Controller behaviors to perform *CRUD actions.
?
CRUD::Create, Read, Update, Delete
(I've recorded a Video over Entities and Controllers, Discussing Entity, Its Providers, Entity Relations and Entity State) Download Link Basics of Entity, Provider, Relationships and EntityStates
如何定义实体
.netTiers uses the notion of the entity along with the TableModule & Data Transfer Object (DTO) Patterns in order to expose your database as entities. Meaning, for every table in your database, an entity will be generated for that table. The DTO allows you to pass the lightweight entities through the many tiers while still maintaining the loosely coupled open ended architecture of the Entity Layer, since it doesn't depend on any DataProvider.
.netTiers will also attempt to discover all of the relationships that your table has with other tables in the database and will create child
properties of those relationships. This will build out your entire entity domain. Currently the relationship types supported are one to one, one
to many, and many to many relationships. These relationships make it easy for you to intuitively work with your entities and now have a logical object graph. There are several ways to create a certain relationship, but we'll discuss the rules in the Database Model section.
Example: Customer Entity
///An example object graph of a customer entity looks like this. /// Customer Parent /// Order 1:1
/// OrderDetails //1:M
/// ProductCollection //1:M /// CustomerDemographics //1:M
/// CustomerDemographicsCollection_From_CustomerCustomerDemo //M:M
EntityBase
The entities all inherit from two parent classes, the user class called EntityBase.cs which inherits from EntityBaseCore.generated.cs, the generated class. As mentioned earlier, every .generated class will be generated over and over again, do not modify these classes as your work will be lost when you regenerate your code.
These base classes implement the base behavior across all entities. The EntityBase class provides you with exclusive access to modify the behavior across all entities. You can override our default implementation and these changes will not get overwritten. This is a way for you to make changes and extend the behavior while at the same time, safeguarding your work.
EntityBase The EntityBase classes provide behavior to manage state using the EntityState property.
What is Entity State?
Entity State provides a way to track the current status of an entity in it's entity lifecycle, which differs from the CLR object lifecycle. There are 4 main EntityStates, found in the EntityState enumeration, Unchanged, Added, Changed, and Deleted. You do not have to manually keep track of state, when you modify a property, or create a new entity, or read an entity from the database .netTiers will automatically change the state and keep track for you.
1 ///
Entity LifeCycle
Assuming you have no data in your database, the very first thing you will do is add data to the database. In order to do this, you will have to create a new entity. Let's use the Customer entity that we've generated from the Northwind database, and create a new Customers entity and walk through the different states of the entity, which as mentioned earlier is different than the object lifecycle.
1 ///STAGE 1: Added 2 ///Create a new entity, whose EntityState is EntityState.Added 3 Customers customer = new Customers(); 4 customer.Address = \; 5 customer.City = \; 6 customer.Region = \; 7 customer.Phone = \; 8 Response.Write(customer.EntityState); // EntityState.Added; 9 10 ///Persist 11 DataRepository.CustomersProvider.Save(customer); 12 13 14 ///STAGE 2: Unchanged 15 /// The EntityState has been set to EntityState.Unchanged 16 ///Once we persist the entity, it will refresh the entity from the database 17 ///If there is an identity column in your table that the entity represents 18 /// then the new identity of the inserted value is returned as well. 19 Response.Write(customer.CustomerID); 20 Response.Write(customer.EntityState); // EntityState.Unchanged; 21 22 23 ///STAGE 3: Changed 24 /// By modifying a property the entity will automatically 25 /// change state to an EntityState.Changed state. 26 customer.Region = \; 27 Response.Write(customer.EntityState); // EntityState.Changed; 28 DataRepository.CustomersProvider.Save(customer); 29 30 31 ///STAGE 4: Deleted
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 实体
- NetTiers
- 总结
- 学习
- 最新精选中华书局版初中历史七年级下册第一单元 繁荣与开放的社会—隋唐第3课 盛唐气象习题精选六十三
- 青岛市环保监测行业企业名录2018版127家 - 图文
- 分子作业题答案
- 烛之武退秦师当堂检测教师版
- (欧阳)成本会计B试卷20120601
- 抗菌药物培训考试试题及答案
- 3、《我们和青春对话》
- 金属焊接与切割作业题库
- 透镜和密度
- 七年级数学下册6一元一次方程章末测试(一)(新版)华东师大版
- 小学数学一至六年级数学知识点总结
- 共结晶
- 取方格数类题目
- 2011到2016历年高考数学真题(全国卷整理版)
- 2018年人教新目标版初一下册英语Unit5单元测试题含答案
- 工作分析的方法与技术(第三版) 萧鸣政 课后习题答案 - 图文
- 会议管理制度的通知
- 舞台语言的艺术处理
- 广东省佛山市禅城实验高级中学高中物理第二章圆周运动单元测试粤教版必修2
- 2012年暑期社会实践优秀调研项目申报表