Create an XML file by using LINQ

The XML file is widely used in our development, it is very handy when our application needs to communicate with other application or service. LINQ syntax can be used to create an XML file in our practice. Background Data Source Based on the above data, we have a Car class in our code. In order…

Data Grouping in LINQ

Data Grouping is another feature of LINQ syntax, which can group data based on data collection’s filter element or key character. The keyword used in Data Grouping is group and on. Data Source Manufacturer Sample Car Sample Class Definition Car Class Manufacturer Class Data Grouping Implementation As we can see, we group the data via…

Join Data in LINQ

Sometimes, we need to combine two sets of data in our development. In LINQ, we join data by stitching the common content. The syntax is join A on B.content equals A.content In this case, B.content equal A.content. Data Source Manufacturer Sample Car Data Sample As we can see, the two data sets share a common…

Anonymous Type in LINQ

Anonymous type in LINQ query is useful when parts of the data are needed, especially the output type is relatively large. Convert Data into Object The first step of LINQ process is to turn data into objects. Function ProcessFile() turns the data source into object. Helper function Data Source Data source in this post is…

LINQ Study Note – 02

Three Actions In LINQ, we always work with objects, instead of the data source. Therefore, in the LINQ pattern, we always have three actions. Obtain the data source Create the query Execute the query Regarding the data source, the data source LINQ work with should support generic IEnumerable<T> interface; In other words, LINQ serves as…

LINQ Study Note – 01

LINQ works by using extension methods in C#, as LINQ won’t change the IEnumerator behind the scene. Func and Action Func type is common when we use LINQ to process, fetch and modify data or data collection in C#. Func itself can take 17 generic types as parameters. The last generic type parameter describes the…