How to get LINQ to Autoformat in Visual Studio appropriately? - linq

I am trying to get LINQ queries to autoformat nicely, but they are "outdenting" some queries, which looks ugly and confusing. How do I get LINQ queries to format appropriately?
Here's the offending formatting
Repro CSProj (this is VS 2013 but it also happens in 2012)
My autoformatting options are defaults :

So, it appears out that Visual Studio will not autoformat LINQ queries, most of the time. There are a few occasions where it appears that VS autoformatting makes things worse, but you can avoid those by using these steps.
However, if you use the correct keypresses when building queries, you can have it manually format correctly, and Visual Studio will NOT reformat it.
I've automated this using a vsvim macro, but it will work with any environment.
Poorly Formatted LINQ
Step 1: Pull the second line up
Step 2: Type "Enter" at the correct element to reformat correctly
Step 3: Repeat as necessary for remainder of the query

Related

Is there any tool to get the original query from linq in visual studio 2012?

I searched for the above title many times and I cannot match any tool in visual studio 2012 that can get the original query from linq , I tried Microsoft.VisualStudio.DebuggerVisualizers.dll and others but not working
What I generally do when I need to see the SQL generated, I put a breakpoint on the LINQ line, hover over LINQ expression and copy it.

Visual Studio 2010 Find in Files, Appending Results

Is there a way (setting or extension?) to have the Visual Studio 2010 Find in Files feature append the search results (rather than replace them)?
I realize you can send the result to one of two result screens, but that is cumbersome, and wont work past two result sets.
Using SlickEdit in the past, It was nice to just append search results, and just scroll up.

Why do we need to rebuild to update the error list in Visual Studio 2010?

I have a solution with 4 projects, 3 in C# and 1 in VB, and while Visual Studio 2010 catches basic syntax errors in real time, many other errors do not disappear once they are fixed, but until I rebuild the solution.
With pure VB solutions I had never seen this behaviour.
Your insight is appreciated.
I'm using Visual Studio 2008 But I've worked with 2010.
Syntax errors are a lot easier to catch and this is done in not only 2010, but 2008 as well. If you're missing a semicolon or a bracket, the text EDITOR is pointing it out for you. The error list is something that the compiler is telling you to fix. Unfortunately, the compiler doesn't have real-time capabilities. (that'd be too cool.)
The editor is taking care of basic syntax errors (which is do-able in real time) but logical errors or implicit casts cannot be detected until you go through it with the compiler. It's not really much of a reason of why you need to rebuild to update the list, you always rebuild. It's the only way you know for sure that you've fixed the error or not. I find myself habitually pressing: ctrl+s, f6, f5.
I hope this answers your question a bit, there is nowhere that explicitly says why you need to rebuild to update the error list, but that's just the way it is. ^^
Happy coding!

Debugging Visual Studio 2010 Templates

I'm using the visual studio POCO Template for the Entity Framework, so far it has worked great, but since my database/tables are not Upper Cammel Case, but UPPER case, every time that i need to regenerate the entities, i also need to (manually) change the entities on the edmx to be upper cammel case... which is really annoying
what i would like to do is to change the template to translate the Database tables and columns to upper cammel case E.G.
MY_TABLE_NAME => MyTableName
For that i need to understand how the template (tt file) works, and if possible debugg it to know where the change needs to be made.
Thanks!
Grab a T4 template editor from the visual studio gallery. Don't worry, they all suck in one way or another.
A T4 template is about as complex as an ASPX page without codebehind. Its pretty simple to edit them. As for debugging, I believe you have to spin up one instance of Visual Studio and debug it by attaching another instance. Its a bit of a daunting task for someone without a lot of experience.
Depending on yours, the best thing might be to create a simple console application that has a single method to adjust your table names, then copypaste (please don't downvote me!) that method body into your T4 template.
You can include in the T4's C# code a call to
System.Diagnostics.Debugger.Break();
then when executed will "hit" the breakpoint, and ask to attach the debugger, attach Visual Studio (the 2nd Visual Studio will be debugging the first Visual Studio).

Can I use different brace styles in different projects/solutions in VS2008?

I'm working with a couple of open-source projects that use different C# brace styles, and I'd like to configure VS text formatting to use different styles for each project so I can use Ctrl-K-D to reformat source code.
Is there any way I can configure Visual Studio 2008 to load a particular set of text formatting preferences along with a particular solution file?
As far as i know, there is no way to do this natively in VS 2008 (or even 2010 for that matter)
There is a resetsettings command line switch in Visual Studio which you can use to indicate what settings it should start up with. This works in 2005 and i presume it would with 2008 as well though i have personally not tried it with 2008. If you just make a bat file using this method as indicated here, that might be one workaround to your problem.
Also, there is an option to do a macro based solutions that might help you that i remember looking at in the past.You can probably check out this site which indicates how to do something very similar to what you are looking for

Resources