Day 1 at Entity Framework

本文深入解析ADO.NET Entity Framework 的基础用法与高级特性,包括EntityDataSource控制、QueryExtender控制、存储过程添加、动态数据功能、元数据添加到数据模型等。同时,提供性能调优技巧,如绑定与Eval的区别、EntityDataSource控制性能提升方法、懒加载与激进加载策略、TPH与TPT继承模式、IEnumerable与IQueryable的使用、动态字段控制的实现方式,以及对象上下文与对象状态管理在`SaveChanges`方法中的应用。此外,还讨论了POCO(Plain Old CLR Objects)模式和持久性无知的概念,最后介绍了EDMX文件生成的实体、容器和上下文类的继承关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ADO.NET Entity Framework : http://msdn.microsoft.com/en-us/data/aa937723

Entity Framework Tutorials :  http://www.asp.net/entity-framework/tutorials

Beginner Guidehttp://msdn.microsoft.com/en-us/data/ee712907


Class 1 : Getting Started with the Entity Framework

Note: The hands-on lab is teaching

1.  the usage of EntityDataSource control that bind to entity framework. Detail instruction about its properties, e.g. (where,order,group,select,includes and its event e.g.OnSelected event,navigation property update

2. QueryExtender control

3. Add store procedue to Entity framework

4.  Dynamic Data functionality+ Adding Metadata to the Data Model (partial class)


Class 2: Continuing with the Entity Framework

Note: The hands-on lab is teaching

1. ObjectDataSource control, and implement n-tier design like Business-Logic, Data Access(Repository), Unit Test

2.the difference between a business-logic class that includes data-access logic without a repository and one that uses a repository.



Tips:

1) Bind vs Eval   

The Bind expression makes the data available in GridView control properties in case you need to access the data in code. In the page you don't need to access this data in code, you can use Eval

2) EntityDataSource control performance concert: 

change "ConnectionString="name=SchoolEntities" DefaultContainerName="SchoolEntities"" to ContextTypeName="ContosoUniversity.DAL.SchoolEntities"

3) lazy loading vs eager loading

 When you use the ContextTypeName attribute of the EntityDataSource control, the Entity Framework automatically retrieves information for a navigation property when you access that property. This is called lazy loading.
 But sometimes it'cs more efficient to retrieve the related data along with the entity itself in a single call to the database. This is called eager loading

4) TPH & TPT

This pattern of generating an entity inheritance structure from a single database table is called table-per-hierarchy (TPH) inheritance.
This pattern of generating an entity inheritance structure from separate tables for each type, with each separate table referring back to a table that stores data common to all types, is called table per type (TPT) inheritance.

5) IEnumerable vs IQueryable 

The GetDepartments method returns an IEnumerable object rather than an IQueryable object in order to ensure that the returned collection is usable even after the repository object itself is disposed

 6) DynamicField controls

 use DynamicField controls so that you can take advantage of automatic data formatting and validation functionality.For these to work, you will have to call the EnableDynamicData method in the Page_Init event handler.

7) object context & object state manager in SaveChanges method
object context's object state manager, When you read an entity, the object context stores it in the object state manager and keeps track of whether that representation of the object is in sync with the database.Then when you call the SaveChanges method, the object context knows what to do in the database because the object state manager knows exactly what's different between the current state of the entity and the state of the database.

 8)POCO (Plain Old CLR Objects)
 Persistence Ignorance means that the business logic itself doesn't know about persistence. Or in other words, persistence is separated from logic.

9) class generate from *.edmx file 
 all model entity inheritance entity object
 entities container inheritance object context
- each entity model is an object set
all partial class


10) edmx XML 
default edmx class include meta data + designer position information
meta data include 3 sessions
so, connection strig meta data value has 3 parts: csdl,ssdl,msl => 3 files

11) T4: text template tranformation toolkit
template: 
Ado.net entityobject generator
POCO object:ADO.NET POCO entity generator
(model not inheritance from entity object which related to entity framework run time)

and generate 2 tt fies
Model1.Context.tt
Model1.tt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值