Domanda

In my last question, i successfully to dump the data into combo box with solution from Leo but now, i want to get everything of specific user and store into generic list. i tried with this code but it's not working. May i know is there something wrong with my code ?

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

this is in the domain context.

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

this is the generic list store in helper folder

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

Thank you for reply

È stato utile?

Soluzione

AdminInfo is not the same type as tblAdmin so you need to manually create a new list:

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*/});
    }

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top