现在的位置: 首页 > 综合 > 正文

NHibernate 做个小项目(一 )无心之柳

2013年01月22日 ⁄ 综合 ⁄ 共 2836字 ⁄ 字号 评论关闭

只有在实际运用中才能真正的遇到问题 ,并在解决问题的过程中不断提高
在网上参考了 http://blog.aspcool.com/tim/posts/1133.aspx
                          http://nhibernate.3yee.com/archive/2004/04/26/439.aspx
等多篇文章后
所以 打算写基于NHibernate 的一个小小的留言本,
首先 建数据库


CREATE TABLE [dbo].[G_guestbook] (
    
[id] [int] IDENTITY (11NOT NULL ,
    
[userid] [int] NOT NULL ,
    
[username] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    
[title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    
[article] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
    
[pubtime] [datetime] NOT NULL 
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[G_users] (
    
[id] [int] IDENTITY (11NOT NULL ,
    
[Name] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    
[email] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
    
[password] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    
[flag] [int] NOT NULL ,
    
[regtime] [datetime] NULL 
)

很简单的结构,可以用就行了,
第二步是打开 VS.net 新建一个
guestbook.data的工程 ,在这里不得不感谢飞鹰,提供了cool coder这个好东东啊, 虽然还不是哪么的完美,但是生成的实体类,各 映射文件只要稍加改动就可以加到 我的工程里了,节省了大量的时间啊,
我的两个实体类以及 映射文件

using System;

namespace guestbook.data
{
    
public class  guestbooks
    
{
        
public guestbooks()
        
{

        }



        
private System.String _article;
        
public System.String article
        
{
             
get return _article; }
            
set { _article = value; }
        }


        
private System.Int32 _id;
        
public System.Int32 id
        
{
             
get return _id; }
            
set { _id = value; }
        }


        
private System.DateTime _pubtime;
        
public System.DateTime pubtime
        
{
             
get return _pubtime; }
            
set { _pubtime = value; }
        }


        
private System.String _title;
        
public System.String title
        
{
             
get return _title; }
            
set { _title = value; }
        }


        
private System.Int32 _userid;
        
public System.Int32 userid
        
{
             
get return _userid; }
            
set { _userid = value; }
        }


        
private System.String _username;
        
public System.String username
        
{
             
get return _username; }
            
set { _username = value; }
        }

    }

}

using System;

namespace guestbook.data
{
    
public class  users
    
{
        
public users()
        
{

        }



        
private System.Int32 _flag;
        
public System.Int32 flag
        
{
             
get return _flag; }
            
set { _flag = value; }
        }


        
private System.String _email;
        
public System.String email
        
{
             
get return _email; }
            
set { _email = value; }
        }


        
private System.Int32 _id;
        
public System.Int32 id
        
{
             
get return _id; }
            
set { _id = value; }
        }


        
private System.DateTime _regtime;
        
public System.DateTime regtime
        
{
             
get return _regtime; }
            
set { _regtime 

抱歉!评论已关闭.