如何在 c#、wpf 的 GridController 中将 ICollection 显示为一个字符串

How to show ICollection as one String in GridController in c#, wpf

我有一个包含 ICollection“Phone”的对象“User”。我想在 DevExpress 的 TableView-GridController 的一列中显示它们,如下所示:

<dxg:GridColumn VisibleIndex="2"
        FieldName="User.Phone"
        IsSmart="True"
        ReadOnly="True"
        MinWidth="120"
        Header="Phone" />

我试图在我的实体中创建一个新变量,它在一个字符串中包含所有这些 Phone,如下所示:

[NotMapped]
public string AllPhones
{
   get
   {
      string allPhones = "";
      if (Phone != null) 
      {
         foreach (var p in Phone)
         {
            allPhones += p.Lable + "\n";
         }
      }              
            return allPhones;
   }
}

已将 FieldName="User.Phone" 转换为 FieldName="User.AllPhones" 但它不起作用。

还有另一种方法可以解决这个问题,例如在 DropDownList 中显示 Phones 或显示第一个。

下面是我如何放入 GridController 的数据

var qry = SharedBll.Db.Patient.Take(100);
ContactGridControl.ItemsSource = qry.ToList();

尝试使用 eager loading:

明确包含手机
var qry = SharedBll.Db.Patient.Include(x => x.Phone).Take(100);
ContactGridControl.ItemsSource = qry.ToList();
[NotMapped]
public string AllPhones
{
   get
   {
      string allPhones = "";
      foreach (var p in Phone)
      {
         allPhones += p.Lable + "\n";
      }            
      return allPhones;
   }
}