Start here and quickly go beyond the fundamentals! This series provides the aspiring C# developer a comprehensive experience with the language and concepts associated with the .NET Framework.
By watching 22 hours of fun, personalized video lectures and the associated homework each day, you will have a firm grasp on the basics of both C# and creating SQL Server databases. The creative hands on exercises re-enforce the lessons learned each day.
Each day builds on the topics learned previously and will take someone with no programming knowledge at all to the point where they can build simple applications utilizing Object Oriented Programming principles with inheritance and polymorphism, understand a simple UML Class Diagram and implement that design in code, build normalized relational databases, and use T-SQL to query and update the data.
This series is organized into 10 days’ worth of material:
For the sake of completeness, we included this video to demonstrate how to download and install Visual C# 2010 Express Edition on to a fresh machine sporting Windows 7. If you already have the app installed, you can save 7 minutes of your life and move on to the next video.
In this video Bob demonstrates how to build a simple application in C# (prints “Hello World” to a Windows console) as the basis for a larger discussion on creating new projects and using the Visual C# 2010 Express Edition IDE for basic tasks, running an application, and more.
Building on the previous video, here Bob examines the specifics and importance of each part of the syntax that comprised the simple “Hello World” example. Topics include a first-look at the major parts of the .NET Framework, Framework Class Library classes, methods, and the dot syntax, literal strings, code blocks and the curly brace, namespaces, and basic C# lexical grammar and finally, the IDE’s color coded display.
If you’re following along the Core Curriculum, each day Bob will show you something new about the Visual Studio IDE in Visual C# 2010 Express Edition. Today’s topics include: Intellisense, hovering over keywords, methods and other identifiers, status bar information, adding line numbers down the left-hand column using the Tools | Options dialog (Show all settings), changing code font size and background color, pinning and re-arranging windows, rolling up code using the + / – icons, and finally tracking changes with the left-hand green / yellow vertical stripe.
In this video Bob explores how to declare, initialize and use variables in your code, and begins a preliminary discussion on data types and how values are stored in your computer’s memory.
In this video, Bob explains why you would add code comments — essentially lines of code that are ignored by the compiler when an assembly is built — and demonstrates several different ways to add comments to your code, including single line, multi-line, and automating the process using the Comment / Uncomment IDE toolbar icons.
Building off the code example from earlier in the day, Bob demonstrates how to now use the Console.ReadLine() method to retrieve user input into a variable, and how to then display it back out to the Console window with some additional formatting of the string of characters that’s displayed.
To round out the first day, we now tie together concepts discussed during the course of the day to make programmatic decisions in code based on user input. The if statement is one way to create a decision structure in C# and probably the easiest to memorize and most widely used. After an initial pass at writing the code, Bob adds a short discussion on re-writing our code (refactoring) to make the code more readable and more concise.
In this brief video, Bob explains the scope of a variable you declare in one code block and how “visible” that variable is throughout your application.
If you’re planning on following along with the suggested daily Core Curriculum, each day there will be an assignment that should help to solidify concepts discussed during the course of the day into a “real” project. This video explains the assignment and demonstrates example output or expected results. Today’s exercise requires you to build a simple application that allows a user to type in a series of values to save the world from catastrophic doom. No pressure!
Bob will never leave you hanging. If you get stuck during the homework assignment, you can watch the solution video which demonstrates and explains both the solution to the primary exercise as well as the “stretch goals” for bonus points. BUT DON’T CHEAT … to really learn a programming language — or any foreign language — you must immerse yourself into the language which requires you to “get your hands dirty” and practice writing code.
Day 2 kicks off with an exploration into a few of the major parts of the .NET Framework, including the purpose of the Runtime, the compiler and assemblies, the Framework Class Library (FCL), the Common Intermediate Language (CIL) and more. Then Bob turns his attention to addressing the different phases of software development, compilation and executing and the roles that the developer, the C# compiler and the .NET Framework Runtime play during “design time”, “compile time”, “run time” and during “debugging”.
In this video we dig deeper into the C# language talking about the grammatical structure of a line of code (expressions and statements) as well as the “verbs” (operators). Then Bob creates a list of about a dozen operators that you as the beginning developer must commit to memory. Finally, we talk about what happens when you do not follow the rules of proper C# grammar with regards to the IDE’s warnings and the compilers compilation errors.
Building on yesterday’s discussion of variables, in this video Bob discusses how variables are stored and accessed from your computer’s memory. He discusses the technique of converting numbers into binary values, how C# data types are just “shortcuts” to underlying .NET Framework’s Common Type System definitions for values, and provides a short list of the data types you will probably most frequently be using and thus must initially commit to memory.
In this video we add two more methods for implementing decision structures in our code, including the switch statement and the conditional operator with discussion about the nuances of each approach and when you should prefer one over the other.
Continuing our look at basic C# syntax, we move on to the topic of iteration statements and start with the for statement which allows you to iterate over a code-block a pre-determined number of times, or until the break keyword is encountered. Bob expands the initial example to tie together a common use: adding an if statement in the body of the for’s code block to evaluate the conditions in the current iteration.
In this example, we examine a snippet of code that allows us to open an external text file and iterate through each line of the text file using the while statement. While we don’t want to get too deep into working with external content just yet, this does serve as the means for demonstrating the basic difference between the for and while iteration statements. Also starring in this video: the StreamReader, null, and the not-equal-to != operator.
Arrays are simple variables that store multiple values (or rather, elements of the array), each accessible through an index and the index accessor operator (square brackets [ ] ). This video demonstrates how to declare, initialize and access elements in an array, and demonstrates the use of a third iteration statement, the foreach statement, to loop through a code-block once for each element in the array, assigning the value of the element to a temporary variable.
The focus of today’s IDE exploration session is “debugging”, and so Bob tours features such as: setting and removing break points, hitting break points and stepping through code, viewing values in the Watch window and more.
Day 2′s homework assignment requires you to open a text file filled with important spy information, read it’s contents, reverse the order of the contents and display on screen. An additional “stretch goal” requires you to then write the string back out to a new text file.
Stuck? This was a difficult assignment, and so Bob will help you get un-stuck by demonstrating one approach to solving today’s homework problems. This is especially helpful in solving the “stretch goal” involving both reading from and writing to an external text file.
Leaving the most basic discussions of the C# programming language, we move on to the important topic of object oriented programming which will dominate our understanding of the C# language from here on out. Bob explains the thought process behind object oriented programming, classes, instantiation, fields, properties, methods, “black box programming” (also known as “encapsulation”), and much more.
This video begins to unravel some of the mystery surrounding methods … methods like those we’ve worked with since Day 1. Bob demonstrates how to create methods, defining return values or void methods, defining parameters and how to call methods using the dot notation and method invocation operators. Finally, Bob discusses some terminology that we’ll need to know a couple of days from now … “method headers” versus “method signatures”.
Methods define what an instance of a class can “do”. Fields define the “state” or “attributes” of an instance of a class. First, Bob recalls the earlier discussion of fields and points out the problems in exposing fields “publicly”. This leads to a discussion of encapsulation and using hidden (private) fields to store the values and implement publicly visible properties as the “gate keepers” to prevent the code that is working with an instance of the class (the client) from setting the fields to an impractical or improper value.
In this video we turn our focus solely to the process of creating a new instance of a class, often referred to as “instantiation”. Bob explains the difference between a class and an object, or rather, one instance of a class … explaining how a variable is just a reference to an object stored in the computer’s heap. Bob reinforces this notion by quizzing you on a few code snippets that “play” with this idea of references and objects, and challenges you to think about the method invocation operator ( ) when creating a new instance of an object (he answers it on Day 4 .. see “Constructors”).
In this anticlimactic video, Bob now officially discusses “private” and “public” … even though he has inadvertently discussed the topic a couple of times previously. However, to add a bit of value, he discusses naming conventions for private and public class members (camel case for private members, pascal case for public members) and discusses the use of private methods, also known as “helper methods”.
The secret lives of objects … they have relationships with each other! This video explains two typical types of relationships – aggregation and containment and discusses the nuanced differences between the two. This may not mean much at the moment (other than seeing a demonstration of declaring a field / property in one class using the type defined by a second class) but later will become the basis of “patterns” of class interaction (known as “design patterns”).
Today’s Visual Studio IDE overview is a hodgepodge of ideas … first, Bob explains how to use code snippets to speed up your typing of commonly used structures like creating properties and popular decision and iteration structures. Second, he demonstrates the flexibility of the main area, showing how to manage tab groups in multiple panes, slitting a single code pane, and arranging tabs. Finally, he builds on your debugging skills by introducing the immediate window to display values using the ? operator, and shows how the immediate window allows you to modify variables in memory while the application is paused in debug mode.
Now that we’ve started talking about object oriented programming, Bob thought it would be a great time to gently introduce a common notation for expressing class design and object interactions called the Unified Modeling Language, specifically, the Class Diagram artifact. Bob demonstrates how to explain your design decisions on a napkin or whiteboard to explain what members (fields, properties, methods) that should be added to a class, as well as how to represent a basic (aggregation) interaction between two classes.
We’ve been filling your head will all manner of Object Oriented goodness. Now it’s time for you to take the reins and steer us towards an object oriented solution for a new global spy analysis application. You are given a UML Class Diagram and asked to pull an “all nighter” to write the code that implements the design decisions your team members have agreed on to implement this new spy app. Also, you’re asked to write a small Console window application to demonstrate that your code indeed works!
Did you figure out Day 3′s homework assignment? Awesome! No? Well, don’t worry … Bob shows you one approach to solving the assignment and explains how to interpret every part of the UML diagram into C# code.
Today we begin to see the power of object oriented programming. Inheritance is the second major “tenet” of OO, allowing a developer to create specialized versions of a class. In our example, we take our Automobile example and create a specialized “child” class called Truck, which has all the features of Automobile, but extends it to include truck-specific features as well. Bob explains how to create a derived class, or child class, or rather, how to inherit from a base class, and takes a first-look at why inheritance is so important.
In the previous video we looked at how to inherit a base class’ implementation of properties and methods in the derived class. But what if you need to modify a given method, for example? Suppose the way a Truck works internally is fundamentally different from other types of Automobiles? To accomplish this in C#, you would override a base class’ implementation of a method using the “virtual” keyword on the base class and the “override” keyword on the derived class. This video demonstrates these ideas and explains further why you might want to do this.
Picking up from yesterday’s discussion of the “new” keyword and the process of instantiation, Bob discusses constructors which are methods that automatically are invoked when a new instance of a class is created. Constructors allow you, the developer, to “plug in” and ensure that the new object is in a valid, usable state before it is used in the client code.
When designing classes, sometimes it’s important to provide multiple approaches to invoking a method if you anticipate that the code that will use an instance of your class. Perhaps each approach accomplishes the same task, but in a slightly different manner. Bob demonstrates how to overload a method declaration in order to provide multiple ways to call a method, providing a different set of input parameters for each. In doing so, Bob revisits the previous conversation about the difference between a “method header” and a “method signature”.
In this video we tackle a question that may have been nagging you … if classes require an instance to be created before it can be used, then in our earliest use of the Console class, how is it that we never had to create an instance of the class before utilizing its methods (WriteLine, ReadLine, etc.)? The reason is because those methods were defined as static methods. Bob explains how and why you would create static methods, as well as entire classes, in your applications.
C# 3.0 introduced a shortcut to creating the private field / public property syntax. During initial development, an auto-implemented property can be used to quickly implement this pattern and adhere to the general convention of preferring to use public properties rather than creating public fields. The intent is to re-visit public properties for those fields that require some “gate keeper” logic.
Building on your UML Class Diagram knowledge, this video demonstrates how to describe static methods, properties and entire classes in a class diagram, and two styles for expressing an inheritance relationship, as well as overriding methods in the derived class.
Today’s theme for our Visual Studio IDE overview is “finding a needle in a haystack” … or, in other words, navigating and searching through code to find what you are looking for. The video discusses naming conventions for files, using the Class / Member navigation in the code window, using the Find and Find and Replace panes, using “Go To Definition” and “Find All References” contextual menu options.
Before we conclude the day, Bob sneaks in just one more topic: Enumerations, which are data types that restrict the values of the type to a short list of possibilities. In doing so, Bob discusses the idea of “strongly typed” data versus “weakly typed” data and how enumerations are one way to gain confidence in your code by catching potential errors earlier in the development process.
Day 4′s homework assignment requires you to apply concepts you learned today including C# Constructors, Inheritance, overriding virtual methods on the base class, auto-implemented properties and more. I provide you a UML Class Diagram and you build another application for a top secret spy organization.
Stuck on Day 4′s homework? Bob walks you through a solution for today’s homework assignment.
Building on our discussion of both Arrays and Classes, Bob looks at the pro’s and con’s of using simple arrays to store collections of references to objects through a series of examples. He then introduces the System.Collections namespace, and one type of collection specifically (ArrayList) demonstrating the added features you get by using a Collection rather than an Array to manage a group of objects. But when Bob tries to add a different type of object to the collection, problems start to crop up. This will provide the basis of conversation for the remainder of the day … how to add manage instances of different types who may share something in common (like the Print method). This also provides the basis for a discussion of the third tenet of Object Oriented Programming, namely “polymorphism”.
In C# 2.0, generic collections were added to the language specification allowing for a special kind of collection (in the System.Collections.Generics namespace) that allows you to specific the data type that collection can contain. This is another way to work “strongly typed” further increasing your confidence in the code by catching potential problems during development. Furthermore, you the developer get the benefit of working with data that first does not have to be convert to System.Object and then cast back it’s specific data type before a given item in the collection can be used meaningfully. Bob full demonstrates this powerful concept and outlines its benefits in this video.
This video is the first of three techniques to polymorphically call a method (with the same name, signature, etc.) implemented by two different custom types. This first approach involves simple inheritance. Bob shows how — using a generic collection that accepts a base class type — to add derived classes to the collection and call the method those types share in common.
Building on the previous video, this second approach to polymorphically calling a method on two different types focuses on using abstract classes, which as we’ll see is very similar to the previous implementation (using simple inheritance). Abstract classes provide no base implementation of a given method, relying solely on the derived classes to supply an implementation of the method. Bob discusses both the technique and the reason why you would want to take this approach.
The third approach to polymorphically calling a method on two different types is through the use of interfaces, which does not require that the types are derived from the same base class, or rather, the same “inheritance tree”. Bob explains how to define and use an inheritance, it’s benefits over inheritance, and it’s importance in many design patterns.
Elaborating on the previous discussion of interfaces, this video demonstrates how interfaces can be used to make the methods in your applications flexible enough to work with new custom types you add to your application — as long as they agree to the “contract” defined in the interface. Amaze your friends and neighbors with generic collections that accept interface types, and other mind-broadening ideas.
Today’s Visual Studio IDE overview focuses on the contextual method that implements method stubs defined by interfaces in your new custom types. Bob also shows you how to organize code in your classes by defining #regions.
We’re attempting to keep your object oriented knowledge in sync with their representation in a class diagram. Bob demonstrates how to express abstract classes and interfaces (as well as those classes that implement those types) in UML.
Today’s homework involves intrigue, mystery, mutants, abstract classes and inheritance. Aren’t you just a little bit curious? You’ll write an application implementing the design expressed in a UML Class Diagram (with copious use of abstract classes and interfaces) to analyze mutants, their powers, and the likeliness that they’ll become a clear and present danger to society.
Ok, so you may not be a comic book or sci-fi fan, but this exercise really pushed you to learn abstract classes and inheritance. Couldn’t quite figure it out? Never fear … this video is here to save the day and show you one approach to solving the homework assignment.
One of the great paradoxes of writing C# — to move forward, we’ll have to temporarily move away from C# and on to understanding relational databases, and specifically SQL Server 2008 Express Edition. Bob explains what a database is, why databases are important, explains (IBM researcher) Codd’s thought work in the 1970′s which changed how data can be more efficiently and reliably stored. Topics include first-looks at databases, tables, columns, rows, fields, constraints, relationships, normalization primary / foreign keys and more.
This video demonstrates how to use the tools built into Visual C# 2010 Express Edition (as well as all editions of the Visual Studio IDE) to create a new SQL Server 2008 Express Edition database, how to add tables with columns, add data (rows) and more.
Bob delves deeper into the high level topic of “data integrity” by exploring it’s two material agents in SQL Server: data types and constraints. Bob provides a list of SQL Server datatypes that every developer should commit to memory, with the intent to learn more about other data types later.
In this video, Bob demonstrates how to create a Database Diagram in Visual C# 2010 Express Edition with the ultimate aim of using it to easily create a foreign key relationship between two tables. Along the way, much about the Diagram itself is discussed.
Normalization is the process of deciding how to split data up into the right tables. In this video Bob looks at the first two “forms” of normalization with a couple of sample tables. He also discusses why most developers only choose to normalize to second or third normal form, and why too much normalization is not necessarily a good thing.
Today’s Visual Studio IDE overview focuses further on the built-in tools to manage and work with databases. First, we explore the Query window and see how to visually create a query as well as the back-end Structured Query Language that is generated as a result. Second, we look at the Database Explorer window ad pluck out a few additional features we had not discovered before.
Day 6′s homework assignment is all about creating a database, tables and a foreign key constraint using only the built-in tools in the Visual C# 2010 Express Edition IDE.
Can’t remember a step in building a database, tables and a foreign key constraint using a Database Diagram? No problem … Bob will remind you how in this video.
We’ll start today by installing the SQL Server Management Studio (SSMS) Express, the preferred way to work with the Structured Query Language. Usually a simple installation wouldn’t require a video, however in this case there are a couple of gotcha’s when installing SSMS side-by-side with Visual Studio 2010 Express Edition.
This video demonstrates how to open and execute a SQL script containing potentially dozens or hundreds of lines of code. In our particular situation, Bob wants you, the viewer, to have the same database tables and a thousand rows of data that he’s working with, thus this crucial step in staying synced.
VCS2010_07_02_Sidebar – Bonus: Creating Test Data and Scripting Tables & Data using Third-Party Tools
Curious how (1) Bob created 3000 rows of fake data, and (2) how he scripted the tables and data into a simple script file … in less than 6 minutes? This video shows two third-party tools that make simple work of both tasks. Note: this is not part of the curriculum … Bob is just demonstrating this in case you ever have a similar need.
In this video we look at how to write a simple SELECT statement in T-SQL, explaining the syntax and variations like selecting only certain columns, aliasing column names using the ‘as’ keyword, formatting columns and more.
Continuing our work with T-SQL, we explore the INSERT statement syntax to add rows of data to a given database table. Additionally, Bob shows a second form of the syntax “INSERT INTO” which combines a SELECT and an INSERT.
This video comes with a warning label: be careful! Using the UPDATE statement allows you to change one more more rows of data with new values, but can be very destructive. Bob outlines the proper way to execute UPDATE using a copy / backup of the database and a script that is executed on a live production server only after it’s been thoroughly tested.
The DELETE statement is simple, but lethal. This video shows you the syntax, but moves past that to explain a different technique for removing data that has a built-in safeguard against accidental deletes.
In the case of the SELECT, UPDATE and DELETE statements, the WHERE clause is crucial to working with only those rows of data the meet certain criteria. In this video Bob demonstrates a dozen WHERE operators such as LIKE, BETWEEN, greater than, greater-than-or-equal-to, not-equal-to, IS, IN and more.
When SELECTing data, the order in which the data is sorted can often be important, and this video demonstrates the ORDER BY statement and it’s associated operators.
Till now, we’ve only worked with T-SQL in the context of a single table. What if you need to perform a join (based on the primary / foreign key relationship between the tables) to select some columns from multiple tables? Bob demonstrates the basic syntax of an INNER JOIN, and shows how to add table aliases, and how to add more than two INNER JOINs in a single statement.
Day 7′s homework assignment requires you to write five T-SQL statements based on the Customers and Orders table we used throughout today’s videos. You’ll exercise virtually everything you learned today, including TOP, LIKE, BETWEEN, INNER JOIN and more.
Got stuck on a query or two? Bob demonstrates step-by-step how to work through and solve the T-SQL queries.
In this video we continue our work in SQL Server 2008 Express Edition. We start with a brief conversation about the internals of query execution and query plans and how you can use SQL Server Stored Procedures to view and tweak query performance. Stored Procedures are also a mechanism used by DBA’s to control access to the underlying table data for certain groups of users. We talk about how some organizations choose to use Stored Procedures to encapsulate business rules that must be implemented across the entire organization (as opposed to using shared C# assemblies for this purpose) since stored procedures sit closest to the data. The fourth benefit is that it will relegate the job of data selection and other CRUD opertaions to the tool originally created for that purposes (SQL). We discuss how Microsoft provides many technologies to architect applications around an organizations preferences as well as their business and technical needs and how there is no “one right way” to arch
As the title suggests we spend twenty minutes on the basics of creating stored procedures including basic syntax, using the built-in templates (in case you can’t remember all that syntax off the top of your head). We briefly discuss the BEGIN and END keywords in SQL as what defines code blocks in T-SQL. Next, I demonstrate executing Stored Procedures in a new query window using an ad hoc query. I discuss how to create scripts that ALTER and DROP stored procedures. I spend a few moments talking about “scripting” your database objects and changes and why that is an important skill … namely, to allow the migration of your database from a development to a production environment, tweakability, and source / version control. Finally I discuss naming conventions for Stored Procedures.
This video expands on the previous video demonstrating the use of input parameters, both creating and executing stored procedures that implement them. Similarly we give the same treatment to output parameters and return values and discuss the proper usage for each.
The Visual Studio Express Editions allow you to create and manage two types of databases — a Local and a Service database — to add to your project. This video discusses the differences between those two options, which ultimately are using SQL Server 2008 Compact Edition and SQL Server 2008 Express Edition, respectively. We’ll examine scenarios where each one fits nicely and look at some crossover situations which are really a judgment call on the part of the developer. We compare storage, access, security, programmability and more and end with some guidelines when to use each type of database in your applications.
Most business-related .NET applications will involve data access in some regard. This video explains at a high level those steps that your .NET application must complete to locate, handshake, request and ultimately retrieve data from a data store regardless of the vendor or product. We also lay out the game plan for the next several videos over the next two days that we’ll take to demonstrate the myriad ways available from Microsoft to access data from a database.
In an effort to see a progression from ADO.NET 2.0 to 4.0 and the new style of accessing databases and problems it solves, we begin looking at an example of database access using ADO.NET 2.0 in a Connected scenario, using a Data Reader against a SQL Server Compact Edition database. While you are welcome to use the code here within your own applications, be forewarned that the real purpose of this is not to encourage the use of the older API, but rather to highlight the style and show the evolution (which will be demonstrated a few videos after this one).
VCS2010_08_07 – Retrieving Data with ADONET 2 in a Connected Scenario (featuring SQL Server Express Edition)
This video is similar to the previous one, however in this case we use ADO.NET 2.0 in a connected scenario using a DataReader to work against a SQL Server Express Edition database. As a result, we are forced to use a different connection string and command type (actually, we’ll demonstrate two other command types … Text and StoredProcedure). Again, the purpose of this video is not to commend this as the “one right way” to access a database in 2010, but rather to show a progression of thought in data access strategies enabled by Microsoft in ADO.NET 4.0, Entity Framework and LINQ to Entities (all topics that will be covered soon in subsequent videos.)
VCS2010_08_08 – Managing Data with ADONET 2 in a Disconnected Scenario (featuring SQL Server 2008 Express Edition)
In this video we write A LOT of code to demonstrate how to use ADO.NET 2.0′s DataSet and DataAdapters to work in disconnected mode with a SQL Server Express Edition database. We define INSERT, UPDATE, DELETE and SELECT commands for our DataAdapters so that it can work with changes we made to our data while disconnected from the database. We talk about DataSets as in-memory representations of the tables and data in a database. Your application can both work with the data (as if it were connected directly to it) however also conserve resources with a shared database (including database connections and table locks on the data). We’re working our way towards discussing how the latest incarnation of ADO.NET uses techniques like these (an in-memory representation of data, working disconnected, etc.) to present data as strongly typed objects rather than as relational data.
Finishing up our look at ADO.NET 2.0, in this video we look at creating a strongly typed DataSet using a wizard in Visual C# 2010 Express Edition. We then use that strongly typed version to duplicate the example from the previous video with emphasis on how much less is required AND how much more readable, safe and usable (thanks to Intellisense) it is compared to a not-so-strongly typed DataSet. Then we focus on using a strongly typed DataSet as the basis for a databinding example, using a Windows Form DataGrid to bind to the DataSet. We do write one like of code to save our changes back into the underlying database.
Having demonstrated basic ADO.NET 2.0 scenarios, we now look at two basic ADO.NET 4.0 Entity Framework scenarios (featuring LINQ to Entities) to access data. Much is NOT explained in this video but provides a high level overview of the need that was addressed in EF and contrast it with the ADO.NET 2.0 connected and disconnected approaches. The video demonstrates using LINQ to Entities against a single table, related tables, using LINQ query syntax and method syntax, using the var keyword and more. Also, shows how to create relationships between tables in a Compact Edition database in Visual Studio’s IDE.
At the conclusion of Day 8 we have a challenge that involves the creation of parameterized stored procedures, using ADO.NET 2.0 in connected mode to execute those stored procedures, retrieve and display the results to a Console window with a complex menu-ing system. Good luck! (Solution in the next video, as always.)
Get stuck on Day 8′s homework assignment? This video details how to create the stored procedures, the console application’s menuing system and finally how to connect to the Express Edition database, create the parameters collection, execute the stored procedure and display the results of that interaction in the console window.
In this video we look at a object and collection initializers. They work similarly to an initialized array, where we’re able to set the properties of a newly created object or multiple instances of new objects in a new collection in essentially one line of code. We’ll begin by demonstrating object initializers and then show how to use collection initializers … In some ways it’s similar to a constructor that populates the properties of a newly instance of an object. However, unlike a constructor, you can pick and choose which properties to populate in any combination. We’ll also demonstrate some advanced scenarios like nested initializers and more.
This video continues to explain the building blocks of LINQ by introducing the var keyword, also known as Local Type Inference (or rather, implicitly typed local variables). Local Type Inference is an easy way to declare a variable without having to know the type upfront. When we work with LINQ, many times it may not be very clear what a given LINQ query is returning, and in some cases when you start projecting anonymous types there IS no pre-existing type to use! (I’ll explain what an anonymous type is later in Day 9). And so the var keyword allows us to say “we don’t really care what it is, let C# figure it out.” Now, Microsoft suggests that you use the var keyword to make development easier. Some authors I’ve read insist that you should use it as a temporary measure until you can figure out the exact return type … one technique would be to set a break point and use the debugging tools to figure out what the actual type is. I think they say this because they, like me,
In this video we’ll look at another language enhancement in C# 3.0 and that is Anonymous Types. Anonymous types are are “on the fly classes” … un-named classes … and the key to this is that the compiler “infers” or figures out what the type definition looks like based on the object initializer. You might wonder why you would need such a thing, but they are used extensively when working with LINQ (i.e.,, when projecting results back from a LINQ query), so we want to get our heads around them before we start looking at LINQ examples.
In this video we’ll talk about extension methods which are simply methods — usually helper methods that can be bolted on to the side of existing types / classes … even if that type is sealed, meaning that it cannot be inherited from. Extension Methods also help promote a more fluent style of programming (which we’ll demonstrate and explain in the video.) In the past you may have had some helper methods that are intended for operation on certain types … like a formatting method for example. This is similar in concept, but the implementation is cleaner and more elegant. The reason why Extension Methods are important is because this is how LINQ’s methods, like Select, Where, Sum, Count, are bolted on to the side of types that implement the IEnumerable interface, as well as others. So, Extension Methods are what makes LINQ’s method syntax work.
Typically, we speak of delegates in the context of events. However, since LINQ there’s been a need to understand Delegates in a new context. In the first of a three-part mini series about Lambda Expressions, we use Delegates to explain the first chapter of the Lamda Expression story. Several length, well explained examples highlight how delegates work, what is their purpose, and most importantly, will help us to better understand Anonymous Methods and ultimately Lambda Expressions and their use within LINQ.
In this second in a three-part mini-series about Lambda Expressions we demonstrate how Anonymous Methods can be used to satisfy a delegate input parameter to a method without having to declare a named method that matches the delegate’s method signature … an Anonymous Method is a block of code without a name and can be declared “in line” and passed into a method as an input parameter. How does this help us? The real payoff for this idea is in the next video when we learn about Lambda Expressions, but Anonymous Methods are another step towards that important language element that is used extensively by the LINQ Method Syntax.
This video is the thrilling conclusion to a three part mini-series that culminates in deciphering what a Lambda Expression is, how it is used in LINQ, and also the Func delegate declaration used by Microsoft in LINQ’s Method syntax (that you can use, too!)
In this lecture, Bob explains the benefits and two major styles of LINQ; the Method Syntax and the Query Syntax. Also discussed is the how LINQ is implemented in C#, and how LINQ is used to describe intent allowing the implementation of the given LINQ Provider to take on the responsibility of determining (and executing) the most efficient means of achieving the developer’s intent.
This video demonstrates a dozen short examples to showcase both the Method Syntax and the Query Syntax to perform simple operations against a small sequence of data in an array of strings. Through this example we get a taste for both syntax and will use this a basis for further exploration throughout the remainder of Day 9.
Projection in LINQ is the act of selecting data items from a sequence and shaping them into a new instance of a named type (a .NET Framework type or custom class) OR into an anonymous type. This video demonstrates many different techniques for using the LINQ C# keyword SELECT as a means of projecting your results into new lists of a given type. Even some more advanced projections are demonstrated such as taking an object graph and projecting it into a new XML document — in one line of code! We demonstrate both method and query syntax for all examples.
In this video we demonstrate the use of LINQ’s WHERE clause to filter the data items in a sequence. In addition, we show how to chain WHERE clauses together using the && and || (AND and OR) operators in C#, how to accomplish this using the method syntax and lambda expressions and extension methods, and more.
In this video we’ll look at the FROM and JOIN statements in LINQ. We’ll look at how to retrieve both flattened and hierarchical results, and how to create what we might basically consider both inner and outer joins if this were T-SQL. We’ll over the following C# keywords: join – on – equals and into … and we’ll cover the following extension methods: SelectMany(), Join() and GroupJoin().
In this video we’ve included pretty much every other linq extension method … featuring methods that can help you determine whether there are any items in the sequence at all, or at least, any items that meet a certain criteria, other methods that perform basic operations on the seuqnce … that is the sum, the min, the max, the average and so on, methods that find the first or last occurance of an item in the sequence that meets a certain criteria and so on. We’ll cover: Any(), All(), Contains(), Count(), Sum(), Min(), Max(), Average(), First(), FirstOrDefault(), Last(), LastOrDefault(), Single(), SingleOrDefault() and Aggregate().
This video caps off our jaunt into the land of LINQ. Here you are presented with 9 LINQ challenges and are required to complete each one using the Query Syntax and the Method Syntax. Good luck … you will need it! (If you get stuck, there’s always the solution videos for each part of this exercise!)
This video demonstrates the thought process and the solution for each of the nine LINQ challenges for Day 9 using the Method Syntax.
This video demonstrates the thought process and the solution for each of the nine LINQ challenges for Day 9 using the Query Syntax.
Kicking off Day 10, Bob discusses the Entity Framework in more depth, looking at the Entity Data Model itself and three three XML sections that comprise it, the Storage (or Physical) Model, the Conceptual Model and the Mapping section. We discussed why this extra layer of abstraction between the database and class model that represents it and discovered how it is this feature that gives the Entity Framework its high degree of flexibility. We discuss the Entity Container and how it derives from ObjectContext to give us access to the Entity Classes it contains, we looked at Lazy Loading and talked about best practices for optimizing LINQ queries, especially those involving related data.
In this video we look at the basics of selecting data using both the LINQ query and method syntax including projecting entire entities, a single property of an entity, and multiple properties of the entity into a new anonymous type. We also look at the Object Service’s ObjectQuery.ToTraceString() method to peek in and see the SQL that has been created from the LINQ query.
Continuing on the theme of using LINQ to Entities to select entities from the entity model, in this video we demonstrate how to select data from two related entities, how to select into a shaped hierarchy as well as how to flatten the properties of the entities, and how to alias properties and entities in the LINQ syntax.
In the third of our LINQ to Entities “select” mini-series I talk about selecting a single item from a sequence of our entity objects using First and FirstOrDefault extension methods, demonstrating the difference and how to utilize the “Default” if LINQ query returns an empty sequence. We also briefly look at the order by and where clauses, and look at some shortcuts when working with the FirstOrDefault extension methods, employing an overloaded version that allows us to specify a predicate (where clause).
VCS2010_10_05 – Inserting Entities Part 1 – Basic Syntax and Problems With SQL Server Compact Edition and Identity Columns
Up to this point we’ve been demonstrating the Entity Framework using a simple SQL Server Compact Edition database with a Customers and Orders table, primary keys that are identity columns, etc. We begin this video with a simple demonstration and explanation of creating a new instance of an entity, populating its properties, calling AddTo__ and then calling SaveChanges. However, we discuss why the code refuses to work with the Compact Edition and some possible remedies. In the next video, we’ll demonstrate the same code we wrote, but using a SQL Server Express Edition version of the database.
VCS2010_10_06 – Inserting Entities Part 2 – Working With SQL Server Express Edition and Inserting Related Entities
In this video we pick up where we left off in the previous topic to demonstrate the same entity insertion code, this time with a SQL Server Express Edition database. Bob reminds the student of the gotcha’s of working with the Express edition and how to see the database changes initiated by our insertion code. He also discusses how the AddTo__ method is deprecated in favor of an ObjectSet syntax in Entity Framework 4.0. Finally, we discuss how to insert related entities and how the Entity Framework is intelligent enough to insert two (or more) records while recording the foreign key value in the related entities.
This video demonstrates how to update an entity and delete an entity (as well as all related child entities) using the Entity Framework.
Wrapping up our basic Entity Framework and LINQ to Entities coverage, in this video Bob demonstrates how to utilize Stored Procedures in EF4, both simple stored procs as well as stored procs that accept input parameters and output a subset of all possible fields from a table. He also demonstrates how to retrieve data into a collection of existing Entities as well as into a new custom complex type.
This video begins another three-part mini series on working with String data. In this video Bob demonstrates how to use the forward-slash character to enable escape sequences for otherwise difficult to represent instructions for literal string formatting. He also shows how to format numeric data into highly formatted strings using different string formatting instructions.
Bob explains what happens in memory when you concatenate string values and how this could lead to inefficient programming. To solve this potential performance issue, Bob demonstrates the use of the StringBuilder class to append values in a memory efficient manner.
In this third of three parts, Bob demonstrates built-in string functions to manipulate and parse through strings. Topics include Replace, ToUpper, ToLower, Length, Trim and more.
In this video, Bob shows how to work with the DateTime class to format a date or time into a properly formatted string, how to create new instances of DateTime for a given date and discusses potential issues when using Parse to create a new DateTime (and prescribes the TryParse method as a safer alternative), how to perform date math, how to use the TimeSpan class to represent the span of time between two dates, and more.
In this final video for the Core 1 – Visual C# 2010 Express Edition video series, Bob explains the thought process behind extracting common code into its own Class Library project and how to reference that new project (the output of which is a .NET Assembly) across two or more projects. As he notes, this is an important building block for future discussions about application architecture, service orientation and more.
For the Day 10 homework assignment you’ll create a project to enter the date and amount for a given purchase. Your program will then calculate the tax, save the data to a database, retrieve the data and display the results to a Console window. Of course if you’re stuck, you can use the solution in the next video to help you out. Good luck!
Get stuck on Day 10′s homework assignment? Never fear! Bob demonstrates step-by-step how to work through and solve the final day’s homework assignment.