0

我正在为 CRM 2011 开发 Silverlight 项目。我有一个由 QueryExpression 产生的 EntityCollection,我需要在数据网格中显示这些实体。

我在网上检查了几个解决方案,但没有一个有效。

我会很感激你的帮助。

4

2 回答 2

1

检查一次。它会工作

    public DataTable GetDataTable()
    {

        DataTable dTable = new DataTable();

        int iElement = 0;
        for (iElement = 0; iElement < ent.Entities[0].Attributes.Count; iElement++)
        {

            string ColName = ent.Entities[0].Attributes.Keys.ElementAt(iElement);
            dTable.Columns.Add(ColName);

        }
        for (int y = 0; y < ent.Entities.Count - 1; y++)
        {
            DataRow drow = dTable.NewRow();
            for (iElement = 0; iElement < ent.Entities[y].Attributes.Count; iElement++)
            {
                string ColNam = ent.Entities[y].Attributes.Keys.ElementAt(iElement);
                drow[ColNam] = ent.Entities[y].Attributes.Values.ElementAt(iElement);
            }
            dTable.Rows.Add(drow);
        }

        return dTable;

    }
于 2014-12-11T05:20:17.663 回答
0

I believe that easiest way is to convert your EntityCollection elements to some typed objects or DataTable and bind it to datagrid. Other approach is to use OData, get data through it and bind this collection to datagrid.

于 2014-02-11T19:36:02.333 回答