Partial Methods

Closely related to partial classes are partial methods, which were introduced as part of the LINQ language features wave in .NET 3.5 and C# 3.0. As with all “partial” features, this you must do with code-generation scenarios, too. The original use case for the feature serves as a good illustration of its purpose. Enter LINQ to SQL.

LINQ to SQL has a designer to create classes corresponding to tables in a database (a form of object-relational mapping). To try this out for yourself, add a new LINQ to SQL Classes file to your project using the Add New Item dialog. An example of a mapping created in the designer is shown in Figure 10.18. A thorough discussion about how to define a LINQ to SQL mapping is irrelevant for our discussion, ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.