Facebook Twitter

WPF ObjectDumper and Linq to Sql deferred loading. Video: WPF Object dumper demo The official C# 3.0 samples are providing a very useful ObjectDumper class that allows displaying any kind of object on the console output.

WPF ObjectDumper and Linq to Sql deferred loading

All the child properties are also displayed and you can even define how deep you want to go through child properties. In this sample, I will show how to achieve quite the same using Windows Presentation Foundation. Actually, I will show two specific technologies: Linq to Sql deferred loadingWPF data driven UI technology (see also this previous post) In WPF, you can define in resources a DataTemplate with a DataType specified but without key. The goal is to display a tree of objects with child properties and so on as long as you expland child nodes.

We could easilly create specific data templates for each type (Customer, Order, etc) : You can notice that the HierarchicalDataTemplate only offers one ItemsSource to go child items. Moq: Linq, Lambdas and Predicates applied to Mock Objects. The Great Linq : LINQ and 3-Tier Dogma. One of the most frequent questions we've received about LINQ to SQL deals with fitting it into the classic three-tiered scenario.

The Great Linq : LINQ and 3-Tier Dogma

That is: Presentation --- Logic --- Data I know someone somewhere is going to accuse me of heresy for what I'm about to state, but it's something I've wanted to get off my chest for a couple years, since I first encountered LINQ to SQL, and started to realize what it meant... The 3-Tier Model is just a pattern. And, like all patterns, It is meant to serve our needs, not the other way around. Don't get hung up on academic concerns such as how many tiers you have in your system. There, I said it. And saying that, I think LINQ to SQL fits perfectly well into the 3-Tier Model.

The spirit of the 3TM is that, in keeping your layers seperate, you achieve the ability to swap out data access, business logic, or presentation interfaces without disturbing the other two (or the functionality that depends on them). Contractual purity is great. Really, that's up to you. That is, Understanding the Linq DataContext. In an earlier post I showed how LINQ developers can connect to a database and write a simple query.

Understanding the Linq DataContext

This post steps behind the scenes of a LINQ to SQL application and describes the classes auto-generated by the Object Relational Designer (aka LINQ to SQL designer). The focus will be on two key items: The Customer and Order entity class The DataContext itself The Customer and Order Entity Classes In the previous post we dragged the Customers class from the Northwnd database onto the LINQ Object Relational Designer. A class called Customer was created. When a developer accesses an instance of the Customer class, it is almost as if they have direct access to the Customer table in the database. Figure 1: The customer table has 12 fields. Here is a portion of the corresponding class generated by the designer, and stored, by default, in DataClasses1.designer.cs. . … Code omitted here The declarations for the fields in the Customer class are very simple, and hence not terribly interesting. Etc … etc… Playing with Linq grouping: GroupByMany ?

Linq is a great technology to manage data directly from your .Net language.

Playing with Linq grouping: GroupByMany ?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier. Then we will show how to use WPF HierarchicalDataTemplate to expose the results in just a few lines. Let's assume we have a collection of customer: 'customers'. Var q = from c in db.Customers group c by c.Country; q then becomes an enumeration of groups (IQueryableEach item of this enumeration defines a group (IGrouping As we can see in its definition, IGrouping is just adding a few things: - the key of the group (country in our sample).- the items grouped by this common key. Foreach (var g in q) { var city = g.Key; foreach (var c in g) Console.WriteLine(c.CompanyName); } IGrouping<,> definition: var q = from g in (from c in db.Customers group c by c.Country) select new { g.Key, Count = g.Count() };

Improving LINQ Code Smell with Explicit and Implicit Conversion Operators. LINQ Framework Design Guidelines. Writing applications that interact with data sources, such as databases, XML documents, or Web Services such as Flickr or Amazon, is made easier in the .NET Framework 3.5 with the addition of a set of features collectively referred to as LINQ (Language-Integrated Query).

LINQ Framework Design Guidelines

In what follows, we start with a very brief overview of LINQ, followed by guidelines for designing APIs in relation to LINQ. 1. A Brief Overview of LINQ Quite often, programming requires processing over sets of values. Some probably well known examples include: extracting the list of the most recently added books from a database of products; or finding the email address of a person in a directory service such as Active Directory; or transforming parts of an XML document to HTML to allow for web publishing; or something as frequent as looking up a value in a hash table.

LINQ allows for a uniform, language-integrated programming model with data, independent of the technology used to store that data. //using SQL-like syntax: