SQL to LINQ converter required, any idea? - c#

We have LINQPad which is great for testing Linq expressions targeting database.
Can any one recommend "free ware" tool, that could help us convert
"Sql Queries" to LINQ expressions
and why you recommend it?
NOTE: Please keep in mind, we use c#.

As far as tool, Randy Minder's suggestion of Linqer is the only direct tool I've seen.
That being said, the Visual Basic team did a very good series showing how to go from SQL to LINQ. This walks through what it takes to learn how to do the conversion yourself. Converting from VB's LINQ to C# LINQ is very easy (most of the statements are nearly identical in LINQ), so it's a good way to learn how to do this, even for C# developers.
Even if you're using a tool, I'd recommend trying to understand the concepts - tools don't always produce the best code. Knowing how to do this yourself is very valuable.

The only tool I am aware of that will do this is Linqer. It is not free, but can be purchased for under $50 I believe. It has worked very well for me.

Related

Prerequisites for creating a project in WPF with C#

I have been thinking a lot lately about making a fully functional project with a small team using C# WPF UI. The goal is to create a construction management software. It is not about "reinventing the wheel", the idea behind this is to gain experience in software programming.
Some of the general knowledge that we possess:
We have been introduced in OOP at the University.
We have programmed in Visual Studio before, but only standard C#.
We watched this playlist of Tutorials on WPF
We have also been looking at some tamplates on Telerik, but our understanding in WPF is too shallow right now to comprehend them.
Some of the things we would love to understand:
What SQL Server would be appropriate for this kind of software, we used Microsoft SQL Server so far.
Any recommendation of books that might help us enhance our skill in building a database such as: reading from it, creating appropriate relation-ships, etc would be greatly appreciated.
Any recommendation of books for C#, LINQ or anything you know and might help us.
We want to treat this project seriously and we know that we will struggle with this documentation step for quite a while. Please let us know if there is any other step or fundamental thing that we missed, thank you!
With WPF you should use MVVM. Unfortunately, there are no good books that will teach you that though.
I have a bunch of articles and samples on TechNet wiki and Gallery. A number of these originated from coaching and teaching newbies.
https://social.technet.microsoft.com/wiki/contents/articles/30959.user-page-andy-oneill.aspx
Some of what's in there ought to help.
Use viewmodel first for navigation.
Don't use pages, use usercontrols and bind content to a property returns a viewmodel.
Template using datatype=vmtype into usercontrols in the ui.
I think redcurry's recommendation of pro c#7 is good. I like Jon Skeet's c# in depth.
For database theory.
Bear in mind it has changed very little in 20 years. Hence rather old books are still good and you can pick up copies really cheap nowadays. For example https://www.amazon.co.uk/dp/0201752840?slotNum=0&linkCode=g12&imprToken=uS5pZKPLsrVEOJop6zd4iA&creativeASIN=0201752840&tag=javarevisit01-21 well worth a fiver.
My big tips on indexing:
By default - add an auto integer as primary key rather than using any natural key you think will "always" be unique. They inevitably change.
Don't add too many indexes.
The old advice is still true. Normalise 'til it hurts and then denormalise 'til it works.
SQL server is good, easy to find online advice and sql express is free. Jobs are very useful but the "full" version of sql server is expensive. If you will have large quantities of sql server and low/no budget then MySQL.
There are free resources for sql server on the web. For example http://www.sqlservercentral.com/
I've never read a book on LINQ. I learnt it as I went by looking up stuff on the web. I rely heavily on intellisense when writing anything isn't fairly simple. My big tip on LINQ is not to use it for complex queries and as complexity increases in one you're writing you should look at the generated sql. Complicated linq is prone to generating terribly inefficient sql.
I really enjoyed the book Pro C# 7. I think it's very well written and comprehensive. It even covers WPF at a reasonable level. There are also chapters on dealing with SQL databases.
Once you're familiar with C# and some WPF basics, you can read Windows Presentation Foundation 4.5 Cookbook. I found that their specific examples and explanations helped me understand how WPF works.
Then it's about getting your hands dirty by trying things out. You'll find a lot of resources online as you search for problems you run into. There are tons of blog posts explaining specific WPF solutions, and of course there's StackOverflow.
Good luck.

How to represent an SQL query in an easily understandable, universal format?

I am planning a C# query tool which is to facilitate the creation of queries, to be used by individuals who have absolutely no knowledge of SQL.
I would like to display the user's query in a format which is easily understandable. Two options which I thought of are Venn Diagrams or natural language. An example of the latter case (to further elaborate on the question) could be:
The user uses the tool and the SQL statement generated by the tool would be something like SELECT SALARY FROM EMPLOYEES.
The tool could display the query as an easily understandable format, such as: "The report is going to display the salary of all employees".
That could be one approach - by using natural language techniques. Another could be by presenting Venn Diagrams, as many people can understand this notation.
Are there any other ways of representing the query, which could be easily understood?
Natural language is probally the best option, Venn Diagrams could confuse people. Easiest approach would be to give a couple of people some SQL training so they can make their own repports and and also act as a gate-keeper for other types of repports they can't make themself. We use this approach and it works very well.
What do you say about Query Trees?
As already commented on other asnwer, Venn diagrams are not easy to understand for eveyone, even less for non technical users. From previous experiences working with clients asking for similar funcionalities I suggest taking a couple of their most advanced users and go hard on them teaching how to use some reporting tool. Configure the tool and let them play a lot with it giving them some feedback and help. Finally after a while, if correctly done, you can leave them on the wild at those advanced users will do the job.

What is a good replacement for MyGeneration / d00dads code generation and data layer?

I have used MyGeneration and the d00dads architecture for several years, and have been a big proponent. The tool is fairly simple and straightforward and the code layer is dead simple.
But a recent experience with it has left me a bit wary now. Support for this software is completely non-existent, any forums dealing with it are virtual ghost towns. I am scared of running into another issue later down the road that I cannot fix and being stuck.
I'm looking for something that:
Explicitly supports MS SQL Server and C#.
Simple: No XML schemas! Straighforward tools. Just convert SQL tables to easily accessible objects and collections
Supported: Developer support is essential. A robust forum community with ongoing bug fixes is ideal.
A year or two ago I would have agreed with the answer to this StackOverflow question. Hell, I may have even upvoted that answer. But I just can't justify that anymore. It's dead software and the source code is complicated enough it's not something you can just dive in and update without prior experience.
Microsoft's Entity Framework?
LINQ to SQL is probably a little simpler, but it's been "officially" replaced by the EF.
** UPDATE **
Here's the 3.5 EF link
Have you taken a look at CodeSmith Generator's Framework templates? I'd recommend taking a look at .NetTiers as it would be a good replacement for d00dads. Other developers have went this route. Otherwise we have the PLINQO templates and soon to be PLINQO for Enity Framework.
Thanks
-Blake Niemyjski (CodeSmith Employee)
I know it's uncouth to answer one's own question, but... after digging into this a bit, the answer became pretty obvious: Entity Spaces is the logical replacement for MyGeneration/dOOdads. Written by the same person, uses a similar syntax and design patterns. Only con is that it is not a free tool.
I realize that this is a very old post, but it still ranks pretty high on DuckDuckGo results.
The MyGeneration guy has created https://www.My2ndGeneration.com. It's not syntax compatible with the first, but it's still pretty nice.

Going from C# to VB.NET - Resources?

Though I have worked with Visual Basic in the past (VB 4, 5, and 6), ever since the .NET framework was first released I have been working in C#. For an upcoming project I am being asked to work in VB.NET so I am trying to come up to speed with VB.NET. Can anyone recommend any resources (books, articles, etc ..) targeted towards C# developers who are looking to quickly become familiar with VB.NET?
EDIT: I feel I should emphasize, due to certain comments, that I am not trying to compare the various worth of each language (C# vs. VB.NET). Such a comparison wold be subjective in so many ways. Rather, I am saying I myself am not that versed in VB.NET and am looking for resources that would enable me to learn VB.NET considering my experience is with C#.
Never, ever forget this when you're doing boolean logic:
AndAlso instead of And
OrElse instead of Or
Just dive in. Seriously, that is the best way to learn. Functionally, they are mostly the same these days.
For me, the major differences are
lack of support for iterators (yield return) in VB.Net (coming in the next version)
XML literals in VB.Net are not available in C#. As a C# developer, many times I prefer VB when working with XML these days...
linq query syntax behaves differently in VB (richer at first sight in VB, but much more consistent in C#)
Other than that, it's mostly just syntax
Oh, and don't forget to put Option Strict and Option Infer on... If you need dynamic, you can 'sort of' get the same by turning off Option Strict (I recommend doing this at the file level).
Here is a link that compares the two languages: http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
In truth with .Net 4.0 they are pretty much the same. The syntax is different (obviously), but their functionality is nearly identical. This is now by design, Microsoft plans on co-evolving them from now on, so new features will be added to both.
I work with both, if you know C# and know VB6 syntax, it'll be easy to pick up (I started with C# since I have more of a C++ background, but I also had some VB6 so it was very easy to start working on VB.Net as well).
There's a few things you'll have to look up every now and then but as Kevin says, they're more or less the same language. And anyway, the languages themselves aren't that big so aren't very difficult to learn, it's learning the .Net Framework that takes a lot of time, so you know what's already written and where to find it, and your knowledge of that transfers across.
go to msdn Visual Basic Developer Ceneter , you'll find tons of information there
http://msdn.microsoft.com/en-us/vbasic/default
here is a learning guide
http://searchwindevelopment.techtarget.com/tutorial/Choosing-VBNET-or-C-Learning-Guide
Google is good for checking syntax differences (search "C# keyword equivalent in vb.net"). MSDN is good about having code examples in both VB and C# too.
This online conversion tool can often be helpful too.
Besides the short circuit operators, one thing that can trip you up is not initializing your variables. It seems like you don't have to, but if you are in a loop you actually do have to.

What Should I know to underestand LINQ better?

As LINQ is a good query language in dot net and everyone should be able to work with it.
What are the necessary abilities which a programmer should have, before start learning LINQ.
And after that, What should he know about LINQ? (important tips)
What kind of Linq are you interested in - Linq to Objects, Linq to SQL, implementing your own Linq provider ?
My advice is that you should first learn about the features that Linq is based upon :
IQueryable and IEnumerable extension methods
Method chaining and deferred execution
Anonymous methods and lambda expressions
Linq query syntax
Expression trees (if you aim at implementing your Linq provider)
Then in turn these features rely on more basic concepts :
Generics
Delegates
Collections
A couple of books that could help you :
C# in depth (J. Skeet) - great book to learn C#
LINQ in Action (Marguerie, Eichert, Wooley)
A decent understanding of Closures / Lambda, IEnumerable, Generics, Expression Trees and Method Chaining, would be a good start. LINQ is pretty much just a utility set based upon that.
But you can definitely learn to utilize LINQ without a solid understanding of each and every single feature mentioned.
If you want to understand the principles behind LINQ than it is very useful to learn some basics of functional programming, because LINQ is largely based on this paradigm. Of course, you don't need that to use LINQ in practice, but it will help you understand what's going on under the cover (not to mention that learning functional programming is said to make you a better programmer anyway).
I wrote an overview article on this topic that you may find useful:
Functional Programming using C# and F#
Aside from functional programming, it really helps to understand all C# 3.0 features, most importantly lambda expressions, extension methods and also expression trees. Technically speaking, LINQ is just a clever combination of these three features, so once you understnad them, you can fully appreciate and benefit from LINQ.
101 LINQ samples really helped me to understand LINQ better http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx?ppud=4
There is a series of videos (8, I believe) Scott Stanfield called "LINQ TO SQL." They are very helpful to understand the concept and how to use LINQ.
Link Here
Or, try google: LINQ TO SQL + Scott Stanfield
I particularly like to use, but little use. is always good care ... but it is very useful. Watch the videos and draws its conclusions.
Enjoy!

Categories