Entity Framework Tutorials 2 —— 学习笔记

Entity Framework Tutorials 2 文章网址 

HtmlHelper 类

描述:表示支持在视图中呈现 HTML 控件。

扩展方法:查看 

 

LinkExtensions 类

描述:表示在应用程序中支持 HTML 链接

方法:ActionLink RouteLink

ActionLink用法可参考Html.ActionLink这篇文章 讲的比较详细。

 

DisplayExtensions 类

描述表示支持以 HTML 形式呈现对象值。

方法

1. Display

    描述:返回由字符串表达式表示的对象中的每个属性所对应的 HTML 标记。

    定义:public static MvcHtmlString Display(this HtmlHelper html,string expression)

    参数:html:此方法扩展的 HTML 帮助程序实例。expression:一个表达式,标识包含要显示的属性的对象。

2. DisplayFor

    描述:返回由 Expression 表达式表示的对象中的每个属性所对应的 HTML 标记。

    详情:查看

3. DisplayForModel

    描述:返回模型中的每个属性所对应的 HTML 标记。

    详情:查看

    备注:都可以在 HtmlHelper 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。

             Display方法 这需要一个表示对象值的字符串来呈现。 DisplayFor方法 需要模型对象。DisplayForModel方法 以隐式方式使用模型。

 

ControllerModelState 属性

   描述获取包含模型状态和模型绑定验证状态的模型状态字典对象

   类型ModelStateDictionary

 

EntityState 枚举

   描述:描述实体对象的状态

   Dached  对象存在,但没有被对象服务跟踪。实体在创建之后且添加到对象上下文之前处于此状态。通过调用 Detach 方法从上下文中移除或者如果使用    NoTrackingMergeOption 加载,实体也处于此状态。  
   Dchanged  自加载到上下文中后,或自上次调用 SaveChanges 方法后,对象尚未修改。  
   Aded  对象添加到对象上下文,SaveChanges 方法尚未调用。通过调用 AddObject 方法将对象添加到对象上下文。  
   Dleted  通过使用 DeleteObject 方法从对象上下文删除对象。  
   Mdified  对象已更改,但尚未调用 SaveChanges 方法。 

 

Prompt:

In a web application this sequence is interrupted, because the database context instance that reads an entity is disposed after a page is rendered. When the HttpPost Edit action method is called, this is the result of a new request and you have a new instance of the context, so you have to manually set the entity state to Modified.

When the SaveChanges method is called, the Modified flag causes the Entity Framework to create SQL statements to update the database row. All columns of the database row will be updated, including those that the user didn't change, and concurrency conflicts are ignored

 

作者:JetWu
出处:http://jetwu.cnblogs.com/
本博原创文章版权归博客园和本人共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出作者名称和原文连接,否则保留追究法律责任的权利。

posted @ 2011-11-16 16:00  JetWu  阅读(253)  评论(0编辑  收藏  举报