0

According to what I've read, to add a calculated Column to display in the ASP DynamicData table, I just need to add a Readonly property to the table class, and set: [ScaffoldColumn(true)] and return the value.

Here's what I did according to those rules, and it does not work:

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;
        }
    }

}

Everything still works, table displays as expected, it's just that I'm not seeing the calculated column.

Thanks!

A.G.
  • 2,089
  • 3
  • 30
  • 52
  • As I remember DynamicData generates fields from the .edmx model itself, rather than from object class, so I suggest you add calculated field to the entity model. – Mihail Golubev Dec 25 '12 at 20:16
  • I think edmx is for when you use the entities framework, I'm using linq to sql, which can also be used with dd. – A.G. Dec 26 '12 at 14:54

0 Answers0