求问Activerecord中数据读取问题!(含代码)
我根据别人的代码写的一个用Activerecord来持久化数据库的测试程序,可以往数据库中添加新项,却不能读取里面的数据。在编译时会显示ActiveRecordException。请各位哥哥帮我看看吧,谢谢。
//实体类
...
...
[PrimaryKey(PrimaryKeyType.Identity, "LongonID")]
public int Id
{
get
{
return _id;
}
set
{
_id = value;
}
}
[Property("LogonName")]
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
[Property("Password")]
public string Password
{
get
{
return _password;
}
set
{
_password = value;
}
}
[Property("EmailAddress")]
public string Address
{
get
{
return _emailAddress;
}
set
{
_emailAddress = value;
}
}
[Property("LastLogon")]
public DateTime LastLogon
{
get
{
return _lastLogon;
}
set
{
_lastLogon = value;
}
}
public static void DeleteAll()
{
DeleteAll(typeof(UserOne));
}
public static IList FindAll()
{
return (IList)FindAll(typeof(UserOne));
}
public static UserOne Find(int id)
{
return (UserOne)FindByPrimaryKey(typeof(UserOne), id);
}
}
}
//显示层
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
isTrue = false;
user = UserOne.Find(1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!isTrue)
{
TextBox1.Text = user.Name.ToString();
TextBox2.Text = user.Password.ToString();
TextBox3.Text = user.Address.ToString();
TextBox4.Text = user.LastLogon.ToString();
isTrue = true;
}
else
{
TextBox1.Text = TextBox2.Text = TextBox3.Text = TextBox4.Text = "";
isTrue = false;
}
}
}
------解决方案--------------------你使用ActiveRecordStarter初始化了没有?
下面的代码是我自己项目中的代码:
C# code
ActiveRecordStarter.ResetInitializationFlag();
XmlConfigurationSource source = new XmlConfigurationSource(Server.MapPath(@"configure.xml"));
// 以下bin\\Domain.Model.dll是包含了你定义ActiveRecord相关类的DLL
ActiveRecordStarter.Initialize(