Contents tagged with LINQ

So, my first course went live on Pluralsight today!
Entitled "The Many Approaches to XML Processing in .NET Applications" this ~4 hour long video course covers the following topics:
- What is this XML Thing Anyway?
- A Myriad of Methods to Read XML
- 16 Ways to Write XML Documents
- Read World Uses of XML
- LINQ to XML Step-by-Step
- Use XML: An Alternative to SQL
If you have ever wanted to work more with XML, then learning LINQ to XML is a great way to do so. This video course will take you step-by-step on the best ways to read and write XML documents.
You can check out this course at http://pluralsight.com/training/Courses/TableOfContents/xml-processing-approaches-dotnet-applications
Enjoy!

Let’s now look at another advantage of using a DataTable. A lot of developers today are used to using LINQ. After loading data into a DataTable you can iterate using a foreach statement, or you can use LINQ to create a collection of entity objects. The DataRow class has an extension method called Field that allows you to check the data and return either a null or the real data value. Of course this means you have to use Nullable types for your properties in your class. Below is the definition of a Product class that uses all Nullable types.

As discussed in my last two blog posts you have a variety of ways to create collections of Entity classes. Using a DataSet or DataTable is a little slower than using a DataReader, but in most cases the difference is in milliseconds so in a real world app this difference would not be a killer. For instance, in my sample data I was loading 6,261 records from the Product table discussed in the last blog post and it took 45 milliseconds on average to load those records into an entity collection using a DataTable. It took only 30 milliseconds on average to load the same entity collection using a DataReader. The rendering of that data would probably take longer than that, so you can choose which one you wish to use.

After my previous blog post, I realized that using SQL strings is not a great way to do things. Sometimes we start blogging too quick and then realize our mistakes after. But, no big deal, live and learn... I am going to now rewrite this application and use some lambda expressions to solve the problems inherit with concatenating strings to SQL statements; namely escaping a single quote and SQL Injection attacks. I am going to use the same search screen shown in Figure 1.