c# - 从 Session.GetObjects 获取列表

标签 c# devexpress

在我的代码中,有一个类:Person .

当我打电话时:

var persons = session.GetObjects(session.GetClassInfo(typeof(Person)), criteria, null, 0, false, true);

persons变量获取 ICollection对象。

问题1:为什么不能使用personsIEnumerable<T>虽然ICollection延伸IEnumerable

问题2:如何构建List实例使用 persons ?我用谷歌搜索了它,ToList()该方法不适用于 persons甚至using System.Linq;存在于代码中。

更新

在代码行上:

IEnumerable<Person> persons = (IEnumerable<Person>)session.GetObjects(session.GetClassInfo(typeof(Person)), criteria, null, 0, false, true);

我收到运行时错误:

Unable to cast object of type 'System.Collections.Generic.List1[System.Object]' to type 'System.Collections.Generic.IEnumerable1[TestProject.BusinessObjects.Person]'.

最佳答案

我看到您正在使用 Session.GetObjects方法。根据文档,此方法支持内部基础结构,不适合直接从您的代码中使用

要从 session 中获取对象,我建议您使用 XPCollection 或 XPQuery:

XPCollection<Person> persons = new XPCollection<Person>(session1, criteria);

关于c# - 从 Session.GetObjects 获取列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50231546/

相关文章:

c# - 我们可以在 Windows 环境中使用 MonoTouch 开发 iOS 应用程序吗?

c# - 如何使属性在 POST 请求上必需,但在 PUT 请求上不需要

c# - 组合框数据库值

c# - DevExpress MVC GridView BindToLINQ() 选择了太多数据

c# - 如何访问 DevExpress XtraTreeList 中绑定(bind)到节点的对象?

c# - 无法在 FormView 的 <EditItemTemplate> 中显示内容

c# - 使用 Microsoft.Exchange.WebServices 的 SSIS 脚本任务

c# - 微软客户关系管理 : Create Address Record Throws Incorrect Attribute Value Type Error

.net - 如何在不使用 cutomunboundcolumn 事件的情况下从图像路径显示 gridview 单元格中的图像?

wpf - wpf中DevExpress的DataGrid控件checkbox列的Checked事件