I often get in a position when I need to know why my LINQ doesnt work as intended...
I use object collections and extensions.
I dont want spend more than couple of minutes on it. LINQ supposed to make developer's life easier not harder.
I hoped VS 2010 will have it fixed but I now use RC and it still doesnt let me type LINQ and check what is going on... Says as before "Expression cannot contain lambda expressions"...
Is there some add-on for Visual Studio so I can quickly and effectively run ad-hoc queries and find out what is going on and where I am wrong?
It's not a VS plugin, but it's free and it's awesome: LinqPad
Check it out here
You can run whatever linq or code snippet in general, just give it a look, it's an incredibly useful tool, for linq and more.
Have you tried this?
Debugging LINQ Queries
Debugging LINQ queries can be
problematic. One of the reasons is
that quite often, you write a large
query as a single expression, and you
can’t set a breakpoint mid-expression.
Writing large queries in expression
context is particularly powerful when
using functional construction to form
XML (or using the strongly typed DOM
in Open XML SDK V2). This post
presents a little trick that makes it
easier to use the debugger with LINQ
queries that are written using ‘method
syntax’.
VS 2010 isn't going to address this..
There is, in fact, such a plugin as you describe, but unfortunately it is highly expiremental. You will probably need to install VS2008 SDK and the Service Packs to get it to work - I know I did..
Here is the link:
http://extendedimmediatewin.codeplex.com/
Related
As an enthusiasting refactorer, there's an IntelliJ feature that I love: "Refactor --> Change signature".
Basically, you have a function and you can decide to remove a parameter or add a new one, setting a default value. This is so convenient, so beautiful, and I dearly love it.
So when I got involved in an oldschool UFT project with maintenance tasks, I felt jaded.
It there a way to achieve this without changing each and every instance of the function? Please tell me yes. Please!
Well, no. I don´t know of any tool capable of this.
There seem to be people who created a C# adapter for the UFT test object API, enabling them to write their tests in C#, and to use VisualStudio for development of test scripts. In VS, you have the refactoring support you look for. But you don´t create UFT scripts anymore, you´d create C# apps. (Note I am not talking about the API testing aspect of UFT, which uses C# anyways -- I am talking about the VBScript test scripts for GUI tests and BPT components.)
UFT itself is not capable of doing real static code analysis. (Let this statement drown a minute, and you´ll agree: it´s true.)
Adding this to the fact that the UFT´s IDE is, let´s say: sub-optimal, this led to the development of Test Design Studio (TDS), a VisualStudio "feel-alike" subset of VS for UFT (VBScript) scripts. You can check it out here: http://www.patterson-consulting.net/products/test_design_studio/Default.aspx
Among other things, TDS does static code analysis for UFT scripts in a pretty complete way (as far as an interpreted variant-typed language like VBScript allows that at all), and the author of the tool seems to be thinking about adding refactoring features like the one you asked for, but -- this has not happened yet. It will probably come only if demand is high.
Until then, TDS could help you:
You could simply change the signature
If TDS knows all calls (which is usually does), it will list you all locations where you need to edit -- and this happens at design-time, not at runtime
TDS allows you to specify the type of identifiers, for example: formal parameters, variables, and so on. This means you might even get warnings if you change nothing about the pure VBScript signature (which does not include type information), but do change the TDS directive of that signature parameter of which you changed the type.
This is no advertisement. I am not part of the company that developed TDS.
This is just an honest answer to the (slightly offtopic) question that I wish would have gotten years ago, asking questions like yours, and it proved to be a real lifesaver.
In summary, TDS quadrupled (or more) my productivity when creating and maintaining test scripts, especially if a large base framework is used. So I´d recommend checking out the option of using TDS to better handle changes like the ones you outlined.
I am working with linqpad and crm 2011, cloud version, and C# snippets. Simple select queries work as advertised. Nonetheless for linqpad to be of any real use I need to get it to do updates and inserts as well and have not been able to find sample code which works or come up with any real information. Several kinds of things which show up in sample code I see around the net are missing. in particular, TestDataContext appears to be part of one or more assemblies which get loaded with linq-sql projects in Visual Studio, but is not in evidence on linqpad. SubmitChanges is not there, and it is not clear what I'd have to do to get at it or to instantiate a new DataContext object and try to use its submitchanges method.
Any usable information would be appreciated.
Well I don't know the CRM 2011 LINQ implementation. Does LINQPad have direct support for that?
Anyway, you basically can run any C# code in LINQPad. Here's a step-by-step guide how to run the needed code:
You need to add the required framework assemblies (maybe take a look at your Visual Studio project). To achieve this, go to the ‘Query’->’Advanced Query Properties’. On the dialog, click on ‘Add…’, then on ‘Browse…’. Browse to the assemblies. Add the required assemblies. Keep the ‘Advanced Query Properties’-dialog open for the next step. Optinally add your own assemblies when you use types from it.
In the ‘Advanced Query Properties’-dialog go the tab ‘Additional Namespace Imports’. Add there the namespaces you need. Expecially the LINQ-namespaces of your LINQ-provider.
Click on ‘Set as default for new queries’ so that you don’t need to repeat the three steps above next time. Then we’re done.
Now you can use the LINQ-provider in LINQ-Pad. Use the 'C#-Statements'-language. Use the .Dump-method to view query results.
Now with that steps you can use any API in LINQPad. With that you can do loops and use the regular API to update objects.
Here's what worked for me in Linqpad for CRM.
Remember that the context is implied in Linqpad.
Create your new entity and load its data, then:
AddObject(entityName);
SaveChanges();
I must say I really like the new code analysis with VS 2010, I have a lot of areas in my code where I am not using CultureInfo.InvariantCultureand code analysis is warming me about this.
I am pretty sure I want to use CultureInfo.InvariantCulturewhere ever code analysis has detected it is missing on Convert.ToString operations.
Is there anyway to get VS to automatically fix warnings of this type?
You cannot do this in VS Code Analysis but CodeIt.Right performs similar analysis (only on source code) and includes auto corrections with every rule. Give it a try!
I don't think you can do that with Visual Studio but Resharper 5 has a Structural Search and Replace functionnality that could work for that.
I heard that R#5.0 (still in beta) will support VS 2010. My question is
VS2010 == VS2008 + ReSharper ?
I know there are many improvements to VS2010, so I 'm not sure weather is it really worth purchasing the R#5.0 for VS2010?
Well, I haven't explored VS 2010 new refactoring features that much, but its my understanding that VS has some but definitely not all of resharpers features implemented (From MSDN):
Navigate To
You can use the Navigate
To feature to search for a symbol or
file in the source code.
Navigate To lets you find a specific
location in the solution or explore
elements in the solution. It helps you
pick a good set of matching results
from a query.
You can search for keywords that are
contained in a symbol by using Camel
casing and underscore characters to
divide the symbol into keywords.
For more information, see How to:
Search for Objects, Definitions, and
References (Symbols).
Generate From Usage
The Generate From
Usage feature lets you use classes and
members before you define them. You
can generate a stub for any undefined
class, constructor, method, property,
field, or enum that you want to use
but have not yet defined. You can
generate new types and members without
leaving your current location in code,
This minimizes interruption to your
workflow.
Generate From Usage supports
programming styles such as test-first
development.
IntelliSense Suggestion Mode
IntelliSense now provides two
alternatives for IntelliSense
statement completion, completion mode
and suggestion mode. Use suggestion
mode for situations where classes and
members are used before they are
defined.
In suggestion mode, when you type in
the editor and then commit the entry,
the text you typed is inserted into
the code. When you commit an entry in
completion mode, the editor shows the
entry that is highlighted on the
members list.
When an IntelliSense window is open,
you can press CTRL+ALT+SPACEBAR to
toggle between completion mode and
suggestion mode.
So I guess it would depend on which of Resharpers features you want to use. If you are satisfied with the above which is certainly great improvements, then you don't need Resharper.
On the performance question, well it might perform better because of tighter integration.
Personally the above leaves me still needing a lot of features like (just the ones i can think of right now - might be more):
There are as far as I can tell only about 6 refactorings, where resharper currently has more than 30
No import type completion, which i use ALL the time. One shortcut adds to references and adds import statement
No smart completion
Change namespace to follow navigation structure and update all references with one shortcut
Goto is more advanced in R# you can go to inheritors and bases,
file member, recent files and edits and theres the fast goto feature
Resharpers static analysis is far more comprehensive than what you get from VS
So what do you need? (I am definitely not giving up Resharper)
Peter,
Best person that can answer this question is yourself. What I suggest is you download it, learn it (and note I said learn it, not just play with it). Then decide. However, I'll warn you that it's quite addictive.
My question is VS2010 == VS2008 + ReSharper ?
Oh hell no. VS2010 has more features than VS2008, and some of those feature ideas were stolen from ReSharper, but vanilla VS2010 is still a long way behind VS2010 + ReSharper 5 or even VS2008 + ReSharper 5.
From a quick glance at my 31 Days of ReSharper blog posts (written back in the R# 2.5 days), here are just a few ReSharper features that are still not present in VS2010: (Please correct me if VS2010 does have any of these -- I haven't actually used it that much without ReSharper!)
Unused code highlighted in gray and with quick-fixes to delete the unused code for you (this is just one of many hints and warnings R# does that VS does not)
Visual indication of where you have hints, warnings, and errors in a source file (colored stripe next to the vertical scroll bar)
Integrated unit-test runner that's not locked down to only MS's test framework
Shared settings for code formatting, code templates, etc. -- check these settings into version control, and they'll be picked up automatically by other computers (no manual export/import)
Go To Type -- a pop-up window where you can enter a type name (or part of the name) and jump straight to the right source file
Navigate to derived types / overriding methods
Code Structure View -- view a list of members in your type, and drag/drop to reorder them in your source code
R# will suggest variable names for you
You can invoke an Intellisense dropdown that shows types from all namespaces (and then it adds the using for you)
It's eerily good at guessing what you meant when you tell it to fix an error for you
Remove unused braces and Invert If
Generate Code (I particularly like Generate Equals and GetHashCode, even though I use them very rarely)
Viral Rename (if you rename a type, it'll also suggest that you rename any variables that were named after the type)
And best of all, Safe Delete.
Safe Delete rocks.
And that's just the features that R# had in 2.5 when I wrote the 31 Days of ReSharper. They've added plenty of new features since (I just don't have a comprehensive list handy). A couple of my favorites are the background solution-wide analysis, which will tell you in nearly real-time if you have compiler errors anywhere in your solution, and Inspect > Value Origin, which is just wicked cool.
If your having to ask the question, my guess is that you're not using ReSharper to its full potential. Personally I find that R# writes most of my code for me and I feel like a noob using visual studio without it.
YES. unequivocably YES.
After migrating to Visual Studio 2010 we asked our development team if buying Resharper upgrades is worth the investment. The votes were unanimous: yes!
Btw: we use VS2010 Premium and the devteam has its own budget.
Why don't you try out the R# 5 betas and then you can decide if you're using enough of its features to justify purchasing it.
http://confluence.jetbrains.net/display/ReSharper/ReSharper+5.0+Nightly+Builds
ReSharper has been around long enough that developers might purchase the upgrade just out of habit! :)
I recall that when VS2008 was released, R# wasn't quite ready, and there was griping among the .NET community about it. "Must...have...ReSharper!". Heh. Jetbrains appear to be on top of it this time though.
Is the Visual Studio 2008 Object Test Bench useful for anything? Maybe I'm missing something but aside from a flashy version of the immediate window, it doesn't seem like a developer would actually use it for anything.
(And how many people knew it existed in the first place?!)
In case you're wondering, the 'Object Test Bench' is located under 'View / Other Windows' in Visual Studio 2008.
I had never heard of it until you mentioned it - thanks for bringing it to my attention.
I do think it's useful. If I want to see how "stuff" works I usually drop my code into LINQPad and see what sort of results I get by doing a Dump() on the resulting object. Only problem is that you have to copy your whole class and supporting classes in there to get anything more than trivial stuff to work. Also, there's no intellisense in LINQPad.
This looks like it can replace what I use LINQPad for. Quick and dirty playing with the objects.
IIRC, you can use it for load/stress testing, but my only exposure to it was a quick demo way back at the Ready To Launch event for VS2005.
Object Test Bench is good for Unit Testing your code and pretty much lightweight. It exists in VS2005 too. I prefer NUNIT which is more powerful