在my last question中,我成功地使用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; }
}
感谢您的回复
答案 0 :(得分: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*/});
}
}