using System;using Castle.ActiveRecord;namespace Sneal.Gallery.Core{ [ActiveRecord("GalleryUser")] public class GalleryUser : ActiveRecordBase { private int id; private string fullName; private string login; private DateTime createdDate; public GalleryUser() { } [PrimaryKey(PrimaryKeyType.Native, "GalleryUserId")] public int Id { get { return id; } set { id = value; } } [Property("FullName")] public string FullName { get { return fullName; } set { fullName = value; } } [Property("Login")] public string Login { get { return login; } set { login = value; } } [Property("CreatedDate")] public DateTime CreatedDate { get { return createdDate; } set { createdDate = value; } } public static GalleryUser[] FindAll() { return (GalleryUser[])FindAll(typeof(GalleryUser)); } public static GalleryUser Find(int id) { return (GalleryUser)FindByPrimaryKey(typeof(GalleryUser), id); } }}
using System;using System.Web;using System.Web.Security;using System.Configuration;using Castle.ActiveRecord;using Castle.ActiveRecord.Framework;using Sneal.Gallery.Core;namespace Sneal.Gallery.WebUI{ public class Global : System.Web.HttpApplication { public Global() { this.BeginRequest += new EventHandler(Global_BeginRequest); this.EndRequest += new EventHandler(Global_EndRequest); } protected void Application_Start(Object sender, EventArgs e) { IConfigurationSource source = ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource; ActiveRecordStarter.Initialize(source, typeof(GalleryUser)); } public void Global_BeginRequest(object sender, EventArgs e) { HttpContext.Current.Items.Add("nh.sessionscope", new SessionScope()); } public void Global_EndRequest(object sender, EventArgs e) { try { SessionScope scope = HttpContext.Current.Items["nh.sessionscope"] as SessionScope; if (scope != null) { scope.Dispose(); } } catch (Exception ex) { HttpContext.Current.Trace.Warn("Error", "EndRequest: " + ex.Message, ex); } }
}
using System;using System.Web.UI;using System.Web.UI.WebControls;using Sneal.Gallery.Core;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) txtInfo.Text = "IsPostback = true"; else if (IsCallback) // doesn't work as hoped. txtInfo.Text = "IsCallback = true"; else txtInfo.Text = "Initial page load = true"; }
protected void btnGetUsers_Click(object sender, EventArgs e) { GalleryUser[] users = GalleryUser.FindAll(); foreach (GalleryUser user in users) { lstUsers.Items.Add(user.FullName); } }}
Powered by: newtelligence dasBlog 2.1.8102.813
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Shawn Neal
E-mail