Total Blog Posts: 13

In this blog post you learn how to compare two lists of data and either add to or extract certain data from the lists. You also perform a check to determine if the data contained in the two lists is the same or not.)

#linq #csharp #pauldsheriff #development #programming

In this blog post you learn how to apply some iteration methods to a collection of data. The ForEach() method allows you to iterate over the entire collection and apply an expression to each object. The Skip() methods allows you to bypass a certain amount of objects at the beginning of a collection. The Take() methods allows you to only take a certain amount of objects from the beginning of a collection.)

#linq #csharp #pauldsheriff #development #programming

In this blog post you are going to learn how to use various aggregate methods of LINQ to count, sum, get a minimum and maximum value and get an average value within a collection of data.)

#linq #csharp #pauldsheriff #development #programming

In this blog post you are going to learn how to join two collections together using both inner and outer joins. You are also going to see how to group data by a specific column such as size and view the different products that fall within that size. In addition, you learn a few different methods for retrieving distinct values from a collection.)

#linq #csharp #pauldsheriff #development #programming

In this blog post you are going to learn how to sort the data using the orderby keyword and the OrderBy() method. Sorting data in a descending order and sorting on two different properties is also explored. The where keyword and the Where() method are used to filter data in a collection based on a criteria you specify. There is a myriad of other methods you are going learn about for searching for data in a collection including Find, First, Last and Single. Finally, you learn the methods used to see if a collection contains a certain value.)

#linq #csharp #pauldsheriff #development #programming

Language Integrated Query (LINQ) is a query language built into the C# and Visual Basic languages. This query language allows you to write queries against any collection that supports the IEnumerable or IEnumerable<T> interfaces. LINQ helps you eliminate loops in your code which are typically slow to execute. LINQ also means you have one unified language for querying any type of collection. Type-checking of objects is supported at compile time which means less chance of errors and you also get IntelliSense.)

#linq #csharp #pauldsheriff #development #programming

When people think of having to store data for their applications, a database such as SQL Server immediately comes to mind. However, XML files are very handy for storing data without the overhead of a database. Using XML files to cache often-used, but seldom changed data such as US state codes, Country code, employee types and other validation tables can avoid network round-trips to a database, and potentially speed up your application. In addition, XML files are great for off-line applications where a user needs to add, edit and delete data when they can't connect to a database. To take advantage of XML within your application, you should use LINQ to XML. I am sure you have used LINQ to iterate over other types of collections. LINQ works great to iterate over XML, too. In this blog post you will use LINQ to XML to read state codes from an XML file and display those values on a web page.)

#xml #linq #pauldsheriff #development #programming

In my last blog posts I have been showing you how to create collection of entity objects using code that is custom for each table and object you create. Well, if you use a little reflection code you can shrink this code quite a bit. Yes, we all know that reflection is slow and probably should be avoided in most cases. What I have found out is that loading over 6200 product records into an entity collection still takes less than a second when using Reflection.)

#entitycollections #linq #reflection #pauldsheriff #development #programming

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.)

#entitycollections #linq #pauldsheriff #development #programming

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. Let's now look at one 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.)

#entitycollections #linq #pauldsheriff #development #programming

In previous blog posts I have discussed how to use XML files to store data in your applications. I showed you how to read those XML files from your project and get XML from a WCF service. One of the problems with reading XML files is when elements or attributes are missing. If you try to read that missing data, then a null value is returned. This can cause a problem if you are trying to load that data into an object and a null is read. This blog post will show you how to create extension methods to detect null values and return valid values to load into your object.)

#xml #linq #pauldsheriff #development #programming

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. )

#silverlight #linq #entityframework #pauldsheriff #development #programming

I have been helping a client with a Silverlight application and one of his requirements was to allow his users to be able to query 1 to 5 fields and use different operators for each field. For example, they can choose to search for a Company Name that 'Starts With' a certain value and also search for an Email field that 'Contains' another value.)

#silverlight #linq #entityframework #pauldsheriff #development #programming