初次体会castle ActiveRecord

本文分享了使用Castle框架实现类似于Hello,World功能的经验,通过少量代码实现了GridView展示及新增功能。文章详细展示了具体的代码实现,并记录了调试过程中的心得。

终于,用Castle调试出类似Hello,World功能。
当正确的结果出来后,感觉比较震撼。实现同样的功能,代码少得令人难以置信。
以下代码是显示一个GridView,包括新增功能。
还有很多问题要慢慢摸索。

User.cs
using System;
using Castle.ActiveRecord;
using NHibernate.Expression;

// This is file is provided just as a starting point
// especially if you are new to ActiveRecord
//
// Feel free to delete it right away.

namespace ARExamWithAspnet
{
[ActiveRecord("Users")]
public class user : ActiveRecordBase<user>
{
private int _LogonID;
private string _LogonName;
private string _Password;
private string _EmailAddress;
private DateTime _LastLogon;

[PrimaryKey]
public int LogonID
{
get { return _LogonID; }
set { _LogonID = value; }
}

[Property]
public string LogonName
{
get { return _LogonName; }
set { _LogonName = value; }
}

[Property]
public string Password
{
get { return _Password; }
set { _Password = value; }
}

[Property]
public string EmailAddress
{
get { return _EmailAddress; }
set { _EmailAddress = value; }
}

[Property]
public DateTime LastLogon
{
get { return _LastLogon; }
set { _LastLogon = value; }
}
}
}

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ARExamWithAspnet;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//LastLogon.Text = DateTime.Now.ToShortDateString();
BindData();
}
}

protected void btnSave_Click(object sender, EventArgs e)
{
try
{
user testUser = new user();
FormBinding.BindControlsToObject(testUser, this);
testUser.Create();

BindData();
}
catch (Exception x)
{
Response.Write(x.ToString());
}
}

protected void BindData()
{
this.GridView1.DataSource = user.FindAll();
this.GridView1.DataBind();
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值