Demo: Include Tags Using Linq

For this demo we'll go straight into the Conduit.Repository Project and open the Articles Repository Class. Find the method called Article Mapper and expand it.

This method is working perfectly fine. We just happened to leave out the tags. I did this on purpose so we can focus entirely on Linq Expressions.

Let's add a new line after mapping the Person and the Article. We'll begin by assigning the expression to the Article Tag List Property.

Linq expression work like this:

  • We need to assign an alias to the source
  • In this case, the source is the Tags from the Editorial object
  • Next we Select the DisplayName Property from the source that is specified by the alias

The result is a Generic IEnumerable of Strings. However, we're looking to get an array of strings for our purpose. We can do so by wrapping the Linq Expression in parenthesis and call the ToArray method which belongs to the Ienumerable object.

Let's give it a quick run for the money and see if it works!

We don't even need to login for this test. Just by calling the GET Articles Endpoint on the API we'll soon know if it worked.

And viola! The Tag List is coming through just as expected!

In the next demo we'll see how we can Delete an Article. I'll see you there!

Resources: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/


I finished! On to the next chapter