0

最後の質問では、Leo のソリューションを使用してコンボ ボックスにデータをダンプすることに成功しましたが、特定のユーザーとストアのすべてをジェネリック リストに格納したいと考えています。このコードで試しましたが、うまくいきません。私のコードに何か問題があることを知っていますか?

  var contexti = new OrganizationContext();
  //contexti.Load(contexti.GetAdminPassQuery(userName), LoadInfo, null);
  EntityQuery query = contexti.GetAdminPassQuery(userName);
  contexti.Load<tblAdmin>(query).Completed += (sender, args) =>
           {
                  List<AdminInfo> list = ((LoadOperation<tblAdmin>) sender).Entities.
                                         ToList();}

これはドメイン コンテキストにあります。

    public IQueryable<tblAdmin>  GetAdminPass(string adminId)
    {
        return this.ObjectContext.tblAdmins.Where(e => e.adminID.Equals(adminId));
    }

これは、ヘルパー フォルダー内の一般的なリスト ストアです。

    public class AdminInfo
{
    public string AdminId { get; set; }
    public string AFirstName { get; set; }
    public string ALastName { get; set; }
    public string AEmail { get; set; }
    public string APassword { get; set; }
}

返信ありがとうございます

4

1 に答える 1

1

AdminInfoはtblAdminと同じタイプではないため、新しいリストを手動で作成する必要があります。

contexti.Load<tblAdmin>(query).Completed += (sender, args) =>
{
    List<AdminInfo> list = new List<AdminInfo>();

    //for each entity returned, create a new AdminInfo and add it to the list
    foreach (var item in ((LoadOperation<Car>)sd).Entities)
    {
        list.Add(new AdminInfo(){ AdminId = item.AdminId, AFirtsName = item.FirstName /*other properties*/});
    }

}
于 2011-11-05T05:47:47.210 に答える