Spring.net的初次使用(4)--关于Model类
首先是表users
CREATE TABLE [dbo].[users] (
[LogonID] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Name] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[Password] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[EmailAddress] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[LastLogon] [datetime] NULL
) ON [PRIMARY]
Entity.cs
using System;
using System.Collections.Generic;
using System.Text;
![]()
namespace Ivan.Spring.Model
{
public abstract class Entity
{
private int _m_id;
![]()
// Methods
public abstract Type GetEntityType();
![]()
// Properties
public int ID
{
get
{
return this._m_id;
}
set
{
this._m_id = value;
}
}
![]()
}
}
Model.cs
using System;
using System.Collections.Generic;
using System.Text;
![]()
namespace Ivan.Spring.Model
{
public abstract class ModelBase:Entity
{
// Methods
public ModelBase()
{ }
![]()
}
}
User.cs
using System;
using System.Collections.Generic;
using System.Text;
![]()
namespace Ivan.Spring.Model
{
public class User:Entity
{
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; }
}
![]()
GetEntityType()
![]()
}
}
User.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Ivan.Spring.Model.User, RunSpring" table="Users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</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>
CREATE TABLE [dbo].[users] (
[LogonID] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Name] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[Password] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[EmailAddress] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[LastLogon] [datetime] NULL
) ON [PRIMARY]Entity.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Ivan.Spring.Model
{
public abstract class Entity
{
private int _m_id;
// Methods
public abstract Type GetEntityType();
// Properties
public int ID
{
get
{
return this._m_id;
}
set
{
this._m_id = value;
}
}
}
}
Model.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Ivan.Spring.Model
{
public abstract class ModelBase:Entity
{
// Methods
public ModelBase()
{ }
}
}
User.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Ivan.Spring.Model
{
public class User:Entity
{
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; }
}
GetEntityType()
}
}
User.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Ivan.Spring.Model.User, RunSpring" table="Users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</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>



浙公网安备 33010602011771号