如何将实体上下文查询对象存储到通用列表中? [英] How to store entities context query object into generic list?
本文介绍了如何将实体上下文查询对象存储到通用列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的最后一个问题中,我成功转储了数据到具有来自Leo的解决方案的组合框中,但是现在,我想获取特定用户的所有内容并存储到通用列表中.我尝试使用此代码,但无法正常工作.我可以知道我的代码有问题吗?
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();}
这是在域上下文中.
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; }
}
谢谢您的回复
推荐答案
AdminInfo与tblAdmin的类型不同,因此您需要手动创建新列表:
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*/});
}
}
这篇关于如何将实体上下文查询对象存储到通用列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文