fsprojects/FSharp.EntityFramework.MicrosoftSqlServer

Name: FSharp.EntityFramework.MicrosoftSqlServer

Owner: F# Community Project Incubation Space

Description: EntityFramework 7 DbContext scaffolding for SqlServer.

Created: 2015-12-20 17:45:02.0

Updated: 2016-11-29 11:49:59.0

Pushed: 2016-09-17 03:37:05.0

Homepage:

Size: 567

Language: F#

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

EntityFramework 7 Sql Server specific DbContext scaffolding for F#.

Background

https://ef.readthedocs.org/en/latest/

Aim

EF7 ships with default CLI-based scaffolding. It works but F# developers can do better by leveraging unique design time mechamism called “Type Providers”.

Constrains of current version
  1. EF7 or later (EF6 is not supporrted)
  2. Sql Server only
  3. Full .NET framework only (Core CLR version will come once F# compiler provides supports for it)
  4. Limitations inherited from current RC1 version of EF7:
  5. no VIEWs support
  6. hierarchyid, sql_variant, geography, geometry, xml are not yet supported
  7. others

Worth noting that type provider doesn't attempt to extend or alter EF7 runtime semantics - it's purely design time tool.

Nuget package

https://www.nuget.org/packages/FSharp.EntityFramework.MicrosoftSqlServer

Sample
 FSharp.Data.Entity

 AdventureWorks = SqlServer<"Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True", Pluralize = true>

db = new AdventureWorks()

nModelCreating <- fun modelBuilder -> 
//override default model here
()

nConfiguring <- fun optionsBuilder -> 
//do runtime configuration here: connection, transactoin etc.
optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=AdventureWorks2014;Integrated Security=True") |> ignore

y {
for x in db.``HumanResources.Shifts`` do
where (x.ShiftID > 1uy)
select x.Name

eq.iter (printfn "Shift: %s")

sert
newShift = 
new AdventureWorks.``HumanResources.Shift``(
    Name = "French coffee break", 
    StartTime = TimeSpan.FromHours 10., 
    EndTime = TimeSpan.FromHours 12.,
    ModifiedDate = DateTime.Now
)

change = db.``HumanResources.Shifts``.Add(newShift) 
recordsAffrected = db.SaveChanges()
rt (recordsAffrected = 1)
rt(change.Entity.ShiftID > 0uy)

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.