搏客 Winning
After three days without programming, life becomes meaningless
posts - 46,  comments - 41,  trackbacks - 21

引用:NHibernate.dll、log4net.dll、HashCodeProvider.dll、Iesi.Collections.dll、Castle.DynamicProxy.dll
App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
        
<configSections>
               
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        
</configSections>
        
        
<nhibernate>
               
<add 
                       
key="hibernate.connection.provider"          
                       value
="NHibernate.Connection.DriverConnectionProvider" 
               
/>
               
<add 
                       
key="hibernate.dialect"                      
                       value
="NHibernate.Dialect.MsSql2000Dialect" 
               
/>
               
<add 
                       
key="hibernate.connection.driver_class"          
                       value
="NHibernate.Driver.SqlClientDriver" 
               
/>
               
<add 
                       
key="hibernate.connection.connection_string" 
                       value
="Server=localhost;initial catalog=NBlog;Integrated Security=SSPI" 
               
/>
        
</nhibernate>
</configuration>

User.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
        
<class name="NBlog.User, NBlog" table="users">
               
<id name="Id" column="LogonId" type="String" length="20"> 
                       
<generator class="assigned">
                       
<param name="property">SignOn</param>
                       
</generator>
               
</id> 
               
<property name="UserName" column= "Name" type="String" length="40"/> 
               
<property name="Password" type="String" length="20"/> 
               
<property name="EmailAddress" type="String" length="40"/>
               
<property name="LastLogon" type="DateTime"/>
        
</class>
 
</hibernate-mapping>

User.cs

using System;

namespace NBlog
{
    
public class User
    
{
        
private string id;
        
private string userName;
        
private string password;
        
private string emailAddress;
        
private DateTime lastLogon;
 
 
        
public User()
        
{
        }

 
        
public string Id 
        
{
            
get return id; }
            
set { id = value; }
        }

 
        
public string UserName 
        
{
            
get return userName; }
            
set { userName = value; }
        }

 
        
public string Password 
        
{
            
get return password; }
            
set { password = value; }
        }

 
        
public string EmailAddress 
        
{
            
get return emailAddress; }
            
set { emailAddress = value; }
        }

 
        
public DateTime LastLogon 
        
{
            
get return lastLogon; }
            
set { lastLogon = value; }
        }

               
    }


}


MainClass.cs

using System;
using NHibernate;
using NHibernate.Cfg;

namespace NBlog
{
    
public class MainClass
    
{
        
public static void Main()
        
{
            Configuration cfg
=new Configuration();
            cfg.AddAssembly(
"NBlog");
            ISessionFactory factory 
= cfg.BuildSessionFactory();
            ISession session 
= factory.OpenSession();
            ITransaction transaction 
= session.BeginTransaction();

            User newUser 
= new User();
            newUser.Id 
= "joe_cool";
            newUser.UserName 
= "Joseph Cool";
            newUser.Password 
= "abc123";
            newUser.EmailAddress 
= "joe@cool.com";
            newUser.LastLogon 
= DateTime.Now;
                       
            session.Save(newUser);
 
            transaction.Commit();
            session.Close();


        }

    }

}
posted on 2005-05-08 14:22 搏客 Winning 阅读(659) 评论(0)  编辑 收藏 所属分类: 项目实践

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2006-02-28 15:52 编辑过


相关链接:
 




与我联系

搜索

 

常用链接

随笔分类

随笔档案

积分与排名

  • 积分 - 30552
  • 排名 - 1325

最新评论

阅读排行榜