在使用caste activeRecord的时候
假设我们有这样的一个类(无限级分类)
/// <summary>
/// 行业
/// </summary>
[ActiveRecord("Trade")]
public class Trade : ActiveRecordBase<Trade>
{
private int _iD;
private string _name;
/// <summary>
/// 父节点
/// </summary>
private Trade parent_;
/// <summary>
/// 了节点
/// </summary>
private System.Collections.IList childList_;
[PrimaryKey(PrimaryKeyType.Native)]
public int ID
{
get
{
return this._iD;
}
set
{
this._iD = value;
}
}
/// <summary>
/// 行业名称
/// </summary>
[Property()]
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
/// <summary>
/// 父节点
/// </summary>
[BelongsTo("ParentID")]
public Trade Parent
{
get
{
return this.parent_;
}
set
{
this.parent_ = value;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return ID.ToString();
}
/// <summary>
/// 子节点 ,进行了级联删除,不进行延迟加载
/// </summary>
[HasMany(typeof(Trade),Table="Trade",ColumnKey="ParentID",Cascade=ManyRelationCascadeEnum.All)]
public IList ChildList
{
get
{
return this.childList_;
}
set
{
this.childList_ = value;
}
}
}
/// 行业
/// </summary>
[ActiveRecord("Trade")]
public class Trade : ActiveRecordBase<Trade>
{
private int _iD;
private string _name;
/// <summary>
/// 父节点
/// </summary>
private Trade parent_;
/// <summary>
/// 了节点
/// </summary>
private System.Collections.IList childList_;
[PrimaryKey(PrimaryKeyType.Native)]
public int ID
{
get
{
return this._iD;
}
set
{
this._iD = value;
}
}
/// <summary>
/// 行业名称
/// </summary>
[Property()]
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
/// <summary>
/// 父节点
/// </summary>
[BelongsTo("ParentID")]
public Trade Parent
{
get
{
return this.parent_;
}
set
{
this.parent_ = value;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return ID.ToString();
}
/// <summary>
/// 子节点 ,进行了级联删除,不进行延迟加载
/// </summary>
[HasMany(typeof(Trade),Table="Trade",ColumnKey="ParentID",Cascade=ManyRelationCascadeEnum.All)]
public IList ChildList
{
get
{
return this.childList_;
}
set
{
this.childList_ = value;
}
}
}
我们希望在用repeater显示的时候
我们希望可以显示出 parent里面的属性 ID或者name
这个时候可以这样子用
父: :::::<%#Eval("Parent") %> 如果没有重写 trade的tostring方法.则会显示出 castle的信息
重写了你想要的属性. 一般我们也只会需一个属性的属性.如果是两个呢?哪么你可以http://www.cnblogs.com/lovebanyi/archive/2006/12/20/598585.html参照一下这个