ASP.NET MVC3 快速入门-第七节 在Movie(电影)模型与数据表中添加一个字段

论坛 期权论坛     
选择匿名的用户   2021-6-2 17:48   394   0
<p>   在本节中我们将要对我们的模型类进行修改,同时介绍如何在ASP.NET MVC3中根据这些修改来调整我们数据表的结构。</p>
<h2 style="text-indent: 0cm; margin: 0cm 0cm 0pt; mso-list: none; tab-stops: 21.0pt;"><span style="font-size: small;"><span lang="EN-US" style="font-family: 宋体; mso-fareast-language: ZH-Cn;">7.1</span> <span style="font-family: 宋体; mso-fareast-language: ZH-Cn;">在我们的<span lang="EN-US">Movie</span>模型中</span><span style="font-family: 宋体; mso-fareast-language: ZH-Cn; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial;">添加</span><span style="font-family: 宋体; mso-fareast-language: ZH-Cn;">一个<span lang="EN-US">Rating(</span>电影等级<span lang="EN-US">)</span>属性</span></span></h2>
<p>    首先,我们在现存的Movie类中添加一个附加的“Rating”属性。打开Movie.cs文件,在Movie类中添加一个Rating属性,如下所示。</p>
<div style="padding-bottom: 4pt; padding-left: 4pt; padding-right: 31pt; background: #f0f7fe; margin-left: 0cm; margin-right: 28.65pt; padding-top: 4pt; mso-element: para-border-div; mso-border-alt: solid #CCCCCC .75pt; border: #cccccc 1pt solid;">
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;">public string Rating { get; set; }</span></span></p>
</div>
<p>    现在完整的Movie类的代码如代码清单7-1所示。</p>
<p>    代码清单7-1 完整的Movie类的代码</p>
<div style="padding-bottom: 4pt; padding-left: 4pt; padding-right: 31pt; background: #f0f7fe; margin-left: 0cm; margin-right: 28.65pt; padding-top: 4pt; mso-element: para-border-div; mso-border-alt: solid #CCCCCC .75pt; border: #cccccc 1pt solid;">
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;">public class Movie</span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;">{<!-- --></span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;"><span style="mso-spacerun: yes;">   </span> public int<span style="mso-spacerun: yes;">     </span> ID<span style="mso-spacerun: yes;">         </span> { get; set; }</span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;"><span style="mso-spacerun: yes;">   </span> public string<span style="mso-spacerun: yes;">  </span> Title<span style="mso-spacerun: yes;">      </span> { get; set; }</span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;"><span style="mso-spacerun: yes;">   </span> public DateTime ReleaseDate { get; set; }</span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;"><span style="mso-spacerun: yes;">   </span> public string<span style="mso-spacerun: yes;">  </span> Genre<span style="mso-spacerun: yes;">      </span> { get; set; }</span></span></p>
<p style="text-indent: 17pt; margin: 0cm 0cm 0pt; background: #f0f7fe; mso-border-alt: solid #CCCCCC .75pt; mso-char-indent-count: 2.0; mso-margin-bottom-alt: auto; mso-para-margin-right: 2.73gd; mso-line-height-alt: 0pt; mso-padding-alt: 4.0pt 31.0pt 4.0pt 4.0pt; padding: 0cm;"><span style="font-size: 8.5pt; mso-fareast-language: ZH-Cn;"><span style="color: #333333;"><span style="mso-spacerun: yes;">   </span> public decimal<span style="mso-spacerun: yes;"> </span> Price<span style=
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP