Castle.ActiveRecord 学与练[3]上

    Castle.ActiveRecord引入了特性映射这个概念,使用 Attribute来代替.hbm.xml文件,从而更加清晰的呈现出了实体类跟数据库表之间的关系,使持久化的数据操作更加简单,易用.
    下面就让咱们一起来通过一个完整的实例了解一下
Castle.ActiveRecord的Attribute.

    我们先来创建三个数据库表,接下来的文章练习都是围绕着这三个表来操作,便于演示一对多,多对一及相应的级联更新,删除等操作.
CREATE TABLE [dbo].[role](
        [roleid] [ int] IDENTITY(1,1) NOT NULL,
        [ name] [ nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
        [permissionlevel] [ int] NOT NULL DEFAULT (1),
        [inserttimestamp] [ datetime] NOT NULL DEFAULT ( getdate()),
        [updatetimestamp] [ datetime] NOT NULL DEFAULT ( getdate()),
CONSTRAINT [PK_role] PRIMARY KEY CLUSTERED    
(
        [roleid] ASC
) ON [ PRIMARY],
CONSTRAINT [UC_role_name] UNIQUE NONCLUSTERED    
(
        [ name] ASC
) ON [ PRIMARY]
) ON [ PRIMARY]
GO

CREATE TABLE [dbo].[users](
        [LogonID] [ int] IDENTITY(1,1) NOT NULL,
        [LogonName] [ varchar](40) COLLATE Chinese_PRC_CI_AS NULL,
        [Password] [ varchar](20) COLLATE Chinese_PRC_CI_AS NULL,
        [EmailAddress] [ varchar](40) COLLATE Chinese_PRC_CI_AS NULL,
        [LastLogon] [ datetime] NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED    
(
        [LogonID] ASC
) ON [ PRIMARY]
) ON [ PRIMARY]
GO

CREATE TABLE [dbo].[userrole](
        [userroleid] [ int] IDENTITY(1,1) NOT NULL,
        [userid] [ int] NOT NULL,
        [roleid] [ int] NOT NULL,
CONSTRAINT [PK_userrole] PRIMARY KEY CLUSTERED    
(
        [userroleid] ASC
) ON [ PRIMARY]
) ON [ PRIMARY]

GO
ALTER TABLE [dbo].[userrole]     WITH CHECK ADD     CONSTRAINT [FK_user_userid] FOREIGN KEY([userid])
REFERENCES [dbo].[users] ([LogonID])
GO
ALTER TABLE [dbo].[userrole]     WITH CHECK ADD     CONSTRAINT [FK_userrole_role_roleid] FOREIGN KEY([roleid])
REFERENCES [dbo].[role] ([roleid])
GO
 

你可能感兴趣的:(.net,orm,IOC,ActiveRecord,Castle)