根据我阅读的内容,要在 ASP DynamicData 表中添加一个计算出的 Column,我只需要在表类中添加一个 Readonly 属性,然后设置:[ScaffoldColumn(true)] 并返回值。
这是我根据这些规则所做的,但它不起作用:
public struct Rep
{
public int ID;
public string Name;
}
[ScaffoldTable(true)]
public partial class RepInfo
{
private static bool IsGotAllReps = false;
public static List<Rep> Reps
{
get
{
IQueryable<int> srID = null;
IQueryable<Rep> srName = null;
if (!IsGotAllReps)
{
using (MiscDataContext dc = new MiscDataContext())
{
srID = dc.MdmSalesAdjustment.Select(s => s.RepID).Distinct();
}
using (DWDataContext dc = new DWDataContext())
{
srName = dc.ReportHierarchy.Select(s => new Rep { ID = s.RepEmployeeID, Name = s.RepFirstName + " " + s.RepLastName }).Distinct();
}
}
IsGotAllReps = true;
return srID.Join(srName, id => id, name => name.ID, (id, name) => new Rep { ID = name.ID, Name = name.Name }).ToList();
}
}
//THIS IS AN EXISTING COLUMN IN THE TABLE THAT I WILL USE TO GET THE REPNAME - SEEL CALC COL BELOW
public virtual int RepID
{
get;
set;
}
//THIS IS THE CALCULATED COLUMN THAT I WANT TO SHOW.
[ScaffoldColumn(true)]
public virtual string RepName
{
get
{
return Reps.Where(r => r.ID == this.RepID).FirstOrDefault().Name;
}
}
}
一切仍然有效,表格按预期显示,只是我没有看到计算列。
谢谢!