丶Terminator 发表于 2013-1-6 02:23:03

设计模式学习日记二(持续更新)

设计模式学习日记二(持续更新)

<div id="cnblogs_post_body">上一篇主要介绍了一些设计原则和模式,本章来详细介绍一下Active Record模式,一个Blog小程序。
导航到http://sourceforge.net/projects/castleproject/files/ActiveRecord/3.0/Castle.ActiveRecord-3.0.RC.zip/download下载ActiveRecord项目的最新版。
创建名为 Terminator.Practice.ActiveRecord 的解决方案,添加名为 Terminator.Practice.ActiveRecord.Model 的C#类库和一个名为 Terminator.Practice.ActiveRecord.UI.MVC 的MVC应用程序(demo中使用的是MVC2.0)。
在解决方案创建一个名为Lib的文件夹,将Castle ActiveRecord下载文件放入其中,为Model项目添加Lib文件夹下的所有引用,MVC项目需要添加Castle.ActiveRecord.dll、NHibernate.dll以及对Model项目的引用。
创建Blog.mdf数据库,两张表Posts(Id,Subject,Text,DateAdd)和Comments(Id,Text,Author,DateAdd,PostId)
向Model项目添加一个Comment类:
<div class="cnblogs_code">using System;using Castle.ActiveRecord;namespace Terminator.Practice.ActiveRecord.Model{        public class Comment : ActiveRecordBase<Comment>   {                     public int Id { get; set; }            public Post Post { get; set; }            public string Text { get; set; }            public string Author { get; set; }            public DateTime DateAdded { get; set; }    }}
页: [1]
查看完整版本: 设计模式学习日记二(持续更新)