Visual Studio 中的 Linq 查询格式

发布于 2024-12-03 19:18:52 字数 875 浏览 0 评论 0原文

在 Visual Studio 2010 中输入以下内容后,

using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from    e in myEntities.Employees
        where   e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select  e;

    ...  Code left out for simplicity ...

我在输入右大括号时遇到格式问题。具体来说,文本编辑器会重新格式化 linq 查询中的空格,以便我最终得到:

using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from e in myEntities.Employees
        where e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select e;

    ...  Code left out for simplicity ...
}

是否可以更改 Visual Studio 的格式设置中的某些内容以防止自动删除 linq 查询中的空格?我尝试过谷歌搜索,并且浏览了工具 -> Visual Studio 的选项窗口但找不到任何内容。希望我只是忽略了一些东西......

提前非常感谢!

After typing the following into Visual Studio 2010,

using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from    e in myEntities.Employees
        where   e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select  e;

    ...  Code left out for simplicity ...

I encounter a formatting problem when I enter the closing brace. Specifically, the text editor reformats the spaces in my linq query so that I end up with,

using(var myEntities = new MyEntities())
{
    IQueryable<Employee> employees =
        from e in myEntities.Employees
        where e.Name == name &&
                e.Password == hasher.ComputeHash(password)
        select e;

    ...  Code left out for simplicity ...
}

Is it possible to change something in the formattings settings for Visual Studio to prevent the spaces in my linq query from being automatically deleted? I've tried Googling this, and I've looked through the Tools -> Options window of Visual Studio but wasn't able to find anything. Hopefully, I just overlooked something...

Many thanks in advance!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2024-12-10 19:18:52

在 VS 中,转到“工具”->“选项”,然后选择“文本编辑器”->“C#”->“格式”->“常规”。至少取消选中此页面上的前两个复选框。这将阻止 VS 自动格式化你的代码。但是,无法仅对 LINQ 查询禁用自动格式设置。

In VS, go to Tools->Options, then Text Editor->C#->Formatting->General. Uncheck at least the first two checkboxes on this page. That will prevent VS from automatically formatting your code. However, there is no way to disable autoformat only for LINQ queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文