Visual Studio中的Linq查询格式

And*_*rew 5 linq code-formatting visual-studio

在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 ...
Run Code Online (Sandbox Code Playgroud)

当我进入右大括号时遇到格式问题.具体来说,文本编辑器重新格式化我的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 ...
}
Run Code Online (Sandbox Code Playgroud)

是否可以在Visual Studio的格式设置中更改某些内容以防止我的linq查询中的空格被自动删除?我已经尝试了谷歌搜索,我已经浏览了Visual Studio的工具 - >选项窗口,但无法找到任何内容.希望我只是忽视了一些事情......

提前谢谢了!

Bre*_*ell 4

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