将 Linq 重新应用到上次 Iqueryable 中的实体

发布于 2024-12-25 19:19:51 字数 989 浏览 3 评论 0原文

这是我的问题:

我有一个 IQueryable 对象,我需要通过在我的 IQueryable 对象中启动相同的包含查询来在 Db 上执行新查询(就像刷新一样) 。 举个例子:

myObj = objCtx.Person
    .Where(p => p.IdPerson...)
    .OrderBy(p => ...)
    .Select(..some field..);
//...
// From another function I just want re-execute 
// the same query
// -> Well, that retrieve full lambda 
var et = this.myObj.Expression
// This doesn't work:
var anotherObj = objCtx.Person.Where(et); 
//or..
var tmp = Expression.Lambda<Func<T, bool>>(et);
// This doesn't work too:
var anotherObj = objCtx.Person.Where(tmp);

有可能实现吗?我缺少什么?

谢谢

好的: 我将能够从 IQueryable 对象检索完整查询(选择语句)并执行它以获得所有更新的数据。

这是原始查询:

this.myIQueryableObj = objCtx.Person
        .Where(p => p.IdPerson...)
        .OrderBy(p => ...)
        .Select(..some field..);

//..And in some button click, I want execute again the above query, but all what I know is myIQueryableObjOnly. Can you help me?

here my issue:

I've an IQueryable object and I need to execute a new query on Db (just like a refresh) by launching the same contained query in my IQueryable obj.
An example:

myObj = objCtx.Person
    .Where(p => p.IdPerson...)
    .OrderBy(p => ...)
    .Select(..some field..);
//...
// From another function I just want re-execute 
// the same query
// -> Well, that retrieve full lambda 
var et = this.myObj.Expression
// This doesn't work:
var anotherObj = objCtx.Person.Where(et); 
//or..
var tmp = Expression.Lambda<Func<T, bool>>(et);
// This doesn't work too:
var anotherObj = objCtx.Person.Where(tmp);

Is it possibile to achieve? What am I missing?

Thanks

Ok:
I would be able to retrieve full query (select statement) from an IQueryable object and execute it in order to get all my updated data.

This is the original query:

this.myIQueryableObj = objCtx.Person
        .Where(p => p.IdPerson...)
        .OrderBy(p => ...)
        .Select(..some field..);

//..And in some button click, I want execute again the above query, but all what I know is myIQueryableObjOnly. Can you help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文