How do you promote and/or sell LINQ syntax t开发者_C百科o colleague that doesn't see the benefit over the manual way of doing thing?
For an example using Linq to Entity/Sql instead of using plain ado.net without any LINQ.
I would personally start with LINQ to Objects. You don't need any buy-in then - you can use LINQ in your code, let him use foreach loops, conditions etc in his code... and eventually he may notice that your code is more declarative, clearer and shorter.
The decision to use an ORM vs plain ADO.NET is a bigger one, IMO - and one with ramifications well beyond just LINQ syntax.
We're running into a similar issue at my place of employment. My argument has been that LINQ is a consistent way of querying anything that supports IEnumerable (and others), not just databases. But, when using it to query databases, you get the added benefit of having all your queries strongly typed. You don't get this when doing inline SQL or calling stored procedures. This benefit is huge when entity definitions changes. The compiler will do all the work for you.
LINQ's great -- but use caution on introducing additional technologies, especially when your company has already settled on a standard. There is nothing more annoying to a developer and costly to a business than having to support 100 different ways of doing the same thing.
I think you could make also make the case that he'd be keeping both the project and his personal skill set in step with the latest tools and developments... just as a bonus to all of the above.
Brown bag lunch session. Project your code on a screen and show how his 20 lines of code can be re-written in 2 or 3.
That's pretty much sold everyone I've shown it to.
Show them my projection demo and ask them how much code it would take to do the same thing in ADO.NET. Then point out that in the real world there would probably be repositories and services in between, which you get nearly free with LINQ projections.
Then show them the parallel extensions in .NET 4.
Tell them that you've reconsidered: you now dislike LINQ and think its an awful way to go.
That should do the trick. Just kidding (mostly).
Some of the benefits:
- You can query not just databases, but XML files or any object collection with the same syntax - this is useful on the long run
- Usign parameters is easier, no need to worry about e.g. SQL injections
- You can query across relationships without having to explicitly join, like this
The biggest benefit of all I would call is the first point, the same and simple syntax.
However if your colleague is an expert in the database field he might not want to switch immediately. LINQ does not bring immediate benefits, especially not on ongoing projects, but it makes you more efficient even on mid term in my opinion.
精彩评论