基于NHibernate的留言本

留言本环境:access2003+  vs2005

 

整个留言本的类视图:

1.新建一个空的解决方案 NHibernateMessage

  依次建立项目Model,DAL,BLL,Command四个项目

2.Model项目处理

删除自动生成的class1.cs文件,新建message.cs文件其代码如下

 

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Model
ExpandedBlockStart.gifContractedBlock.gif
{
   
public class message
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{

ExpandedSubBlockStart.gifContractedSubBlock.gif        
public message() { }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
字段#region 字段
        
private string _id= Guid.NewGuid().ToString();
        
private string _title;
        
private string _username;
        
private string _email;
        
private string _ip;
        
private string _content;
        
private DateTime _addtime;
        
private string _recontent;
        
private DateTime _retime;
        
private int _isshow;
        
#endregion


ContractedSubBlock.gifExpandedSubBlockStart.gif        
属性#region  属性
       [XmlElement(ElementName 
= "id")]
       
public virtual string id
ExpandedSubBlockStart.gifContractedSubBlock.gif       
{
ExpandedSubBlockStart.gifContractedSubBlock.gif           
get return this._id; }
ExpandedSubBlockStart.gifContractedSubBlock.gif           
set this._id=value;}
       }

       
        [XmlElement(ElementName 
= "title")]
        
public virtual string title
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._title; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._title = value; }
        }

        [XmlElement(ElementName 
= "username")]
        
public virtual string username
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._username; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._username = value; }
        }

        [XmlElement(ElementName 
= "email")]
        
public virtual string email
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._email; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._email = value; }
        }

        [XmlElement(ElementName 
= "ip")]
        
public virtual string ip
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._ip; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._ip = value; }
        }

        [XmlElement(ElementName 
= "content")]
        
public virtual string content
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._content; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._content = value; }
        }

        [XmlElement(ElementName 
= "addtime")]
        
public virtual DateTime addtime
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._addtime; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._addtime = value; }
        }

        [XmlElement(ElementName 
= "recontent")]
        
public virtual string recontent
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._recontent; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._recontent = value; }
        }

        [XmlElement(ElementName 
= "retime")]
        
public virtual DateTime retime
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._retime; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._retime = value; }
        }


        [XmlElement(ElementName 
= "isshow")]
        
public virtual int isshow
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get return this._isshow; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set this._isshow = value; }
        }

        
#endregion


    }

}

 

然后在与message.cs同目录下我们新建文件message.hbm.xml一便系统能够关联

message.hbm.xml代码如下【注意:关联xml文件的文件名应该为  关联类名.hbm.xml】

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  
<class name="Model.message, Model" table="tb_message">

    
<id name="id"  column="id"  type="System.String" >

      
<generator class="assigned" />

    
</id>

    
<property name="title"  type="System.String" />

    
<property name="username" type="System.String" />

    
<property name="email"  type="System.String" />
    
    
<property name="ip"  type="System.String" />
    
    
<property name="content"  type="System.String" />
    
    
<property name="addtime"  type="System.DateTime" />
    
    
<property name="recontent"  type="System.String" />
    
    
<property name="retime"  type="System.DateTime" />
    
    
<property name="isshow" type="System.Int32"/>

  
</class>

</hibernate-mapping>

在message.hbm.xml文件配置好后需要注意的是:

message.hbm.xml---右键属性--生成操作--设置为:嵌入的资源

3.web.config配置可以参教demo

demo下载地址:http://files.cnblogs.com/rhythmK/NHibernateMessage.rar

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值