如何使 IQueryable使用常规的 IQueryable 吗?
我正在使用 Linq2SQL 并使用遗留系统。该系统是用 .Net 构建的,但没有数据层,所以我对其进行转码,以便它有一个。我有一个看起来像这样的 linq 查询...
var data = from p in db.tblPeoples
orderby p.strLastName,p.strFirstName
select new
{
guidPersonId = p.guidPersonId,
strFirstName = p.strFirstName,
strLastName = p.strLastName,
strRank = p.tblCodesRank.strDescription,
strPhone = p.strPhone,
strEmail = p.strEmail,
strOffice = p.tblOrganization.strAcronym,
RolesList = p.tblRoles
};
当我检查 var 的签名时,它是一个 IQueryable,我不知道那是什么。在我的数据层中,我将此作为 IQueryable 返回,但是当我尝试使用数据层版本,然后在返回的数据集上执行 .where 进行搜索时,我收到错误,无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型。
我该怎么办?我正在尝试创建代码重用并使用已编写的数据层版本。数据层版本如下所示:
public static IQueryable RetrieveAllPeople()
{
var data = from p in db.tblPeoples
orderby p.strLastName, p.strFirstName
select new
{
guidPersonId = p.guidPersonId,
strFirstName = p.strFirstName,
strLastName = p.strLastName,
strRank = p.tblCodesRank.strDescription,
strPhone = p.strPhone,
strEmail = p.strEmail,
strOffice = p.tblOrganization.strAcronym,
RolesList = p.tblRoles
};
return data;
}
I am using Linq2SQL and working with a legacy system. The system was built in .Net but without a datalayer so I am transcoding it so that it will have one. I have a linq query that looks like this...
var data = from p in db.tblPeoples
orderby p.strLastName,p.strFirstName
select new
{
guidPersonId = p.guidPersonId,
strFirstName = p.strFirstName,
strLastName = p.strLastName,
strRank = p.tblCodesRank.strDescription,
strPhone = p.strPhone,
strEmail = p.strEmail,
strOffice = p.tblOrganization.strAcronym,
RolesList = p.tblRoles
};
and when I check the signature of the var it is an IQueryable and I have no idea what that is. In my datalayer I have this returning as an IQueryable, but when I try to use the datalayer version and then do a .where on the returned dataset to search on it, I get errors that I Cannot convert lambda expresstion to type 'string' because it is not a delegate type.
What should I do about this? I am trying to create code reuse and use my datalayer version that is already written. the data layer version looks like this:
public static IQueryable RetrieveAllPeople()
{
var data = from p in db.tblPeoples
orderby p.strLastName, p.strFirstName
select new
{
guidPersonId = p.guidPersonId,
strFirstName = p.strFirstName,
strLastName = p.strLastName,
strRank = p.tblCodesRank.strDescription,
strPhone = p.strPhone,
strEmail = p.strEmail,
strOffice = p.tblOrganization.strAcronym,
RolesList = p.tblRoles
};
return data;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的返回类型应为 IQueryable ,这是不一样的作为 IQueryable。
为此,您需要创建一个类来填充您的选择,而不是像您一样使用匿名类。
Your return type should be IQueryable<T>, which is not the same as IQueryable.
To do so, you need to create a class to fill in your select instead of using an anonymous one like you do.