Editorials

Linq for Set Logic

How is your skills with Linq? The reason I ask is because I find a lot of set problems work nicely in Linq much as they do in SQL. You can do joins, grouping order aggregation filtering and much more. The concepts are very similar to SQL, but different enough that it takes a little amount o f work to become proficient.

So, why would you consider using Linq in the first place? Many systems benefit from pushing a lot of data manipulation into other application layers than just the database server. Having done so allows you to use that same code with data sources other than SQL engines. It also is not engine specific so you don’t have to worry about the unique implementations of SQL by different engines.

Too, having your set logic in a different tier allows you to use it with non SQL data as well. You simply need to have data that can be resolved as an IEnumerable<> data source. Now you can write your set business logic in one place and use it with so many different data sources.

I have found that you can actually build unit tests with Linq queries as well. This works if you design your set logic to be injected with sets. You can create a Mock set of data to inject into your code and test the output asserting that it meets your requirements. I’m personally enjoying this capability more than anything, because I can create Mock data allowing me to fairly and accurately exercise the requirements.

I’m finding I am able to quickly come up to speed in the syntax because it has enough similarities to the SQL we already know. Are you using Linq? Does it provide advantages for you personally or for your company? What suggestions would you have for someone wanting to learn how to use Linq? Share your thoughts here online, or drop an email to btaylor@sswug.org.

Cheers,

Ben