Chapter 19. Databases

WHAT'S IN THIS CHAPTER?

  • Implementing basic CRUD operations

  • Understanding how ORMs and F# interact

  • Creating your own mapping layer

  • Implementing DDL functionality

There are few, if any, interesting applications that do not use data in one way, shape, or form. If we are to write interesting programs in F#, at some point, it is likely a database will be involved. This chapter explains how databases can be accessed using F# and walks through an example framework for dealing with data in F#.

OVERVIEW

One of the core strengths of F# is processing large sets of data and doing interesting things with it. Most examples where F# was used early on were around things like computation of XBox 360 TrueSkill (http://blogs.technet.com/apg/archive/2008/06/16/trueskill-in-f.aspx). This case, which involves taking a great deal of information gathered from players of Xbox 360 consoles and using said information to produce rankings that allow for smarter matching of players when engaging in multiplayer games, is a canonical use case where F# shines. These cases — where lots of incoming raw information can be processed by complex algorithms to generate business value — are well suited to the F# language.

One thing you might start to notice are the similarities between some of the declarative properties of F# and the declarative nature of the primary languages used for database interaction, Structured Query Language. For example, the select construct in SQL is quite similar to the Seq.map ...

Get Professional F# 2.0 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.