This project is read-only.

Table of Contents

  • Overview
    • Prerequisite
  • Installing NuGet
  • Creating New Project
  • Installing Soma
  • Creating Sample Table and Data
  • Creating Program
  • Executing Program


This document describes how to create simple F# program from scratch.


Following software must have been installed in your computer.

  • Visual Studio 2010 Professional
  • SQL Server 2008 Express

Installing NuGet

Install Visual Studio add-in of NuGet. 

Creating New Project

From Visual Studio menu, Open the "New Project" dialog and create a F# console project. 


Inatalling Soma

Select the "Manage NuGet Packages..." item from the menu.


Enter the string "Soma" into the upper right text box.


Click the "Install" button of the Soma package. When the License Acceptance dialog is open, click "I Accept". 


After installation, the project structure is as follows.


Creating Sample Table and Data

From Visual Studio menu, connect to SQL Server.


Execute following SQL.

use tempdb;

create table Employee (
  EmployeeId integer not null primary key, 
  EmployeeName varchar(20), 
  Hiredate date,
  Salary numeric(7,2),
  VersionNo integer

insert into Employee values(1, 'SMITH', '1980-12-17', 800, 1);
insert into Employee values(2, 'ALLEN', '1981-02-20', 1600, 1);
insert into Employee values(3, 'WARD', '1981-02-22', 1250, 1);

Creating Program

Open the Program.fs file and write following code.

open System
open Soma.Core

let config = 
  { new MsSqlConfig() with
    member this.ConnectionString = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True" }

type Employee = 
  { [<Id>]
    EmployeeId : int 
    EmployeeName : string
    Hiredate : DateTime
    Salary : decimal
    VersionNo : int }

let main args =
  let employee = Db.find<Employee> config [1]
  printfn "before update: %A" employee 
  let employee = Db.update<Employee> config { employee with Salary = employee.Salary * 2M }
  printfn "after update: %A" employee 
  Console.ReadKey() |> ignore

Build the project.

Executing Program

On Visual Studio, press F5 key and execute the program. The console is shown.


Last edited Aug 21, 2011 at 1:35 AM by toshihiro, version 4


No comments yet.