LinqPad不使用C#语句返回结果 [英] LinqPad Not Returning Results With C# Statements

查看:77
本文介绍了LinqPad不使用C#语句返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

太晚了,所以这一定是愚蠢的.我已将LinqPad连接到我的数据库,但似乎无法获得最简单查询的结果.

It's late, so this must be something stupid. I have LinqPad connected up to my database and cannot seem to get results for the simplest of queries.

var q = from app in AppInstances
 select new {
 AppId = app.AppId
 };

运行该命令时,LinqPad表示它已成功执行(C#语句模式).什么都没留.

When I run that, LinqPad says that it executed successfully (C#Statement mode). Nothing is retured.

我可以编写以下非常简单的Lambda(C#表达式模式):

I can write the following very simple Lambda (C# expression mode):

AppInstances.Select (p => p.AppId)

那行得通.为什么?我更喜欢使用非lambda查询构建功能.我敢肯定,这一切都是愚蠢的.

And that works. Why? I would prefer to use the non-lambda query building functionality. I am sure that this is something all together silly.

推荐答案

我希望在语句模式下,您必须执行类似调用q.Dump();的操作才能查看结果.

I would expect that in statement mode, you'd have to do something like call q.Dump(); to see the results.

但是,如果您只想使用查询表达式,为什么不从表达式模式进行查询呢?只需使用以下表达式:

But if you just want to use query expressions, why not do that from expression mode? Just use an expression of:

from app in AppInstances
select new {
    AppId = app.AppId
};

或使其等于您的原始lambda:

Or to make it equivalent to your original lambda:

from app in AppInstances
select app.AppId

这篇关于LinqPad不使用C#语句返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆