title: SQL Type Providers with ROP - F#
body: <p>I'm attempting to use Railway Oriented Programming principals <a href="http://fsharpforfunandprofit.com/rop/" rel="nofollow">http://fsharpforfunandprofit.com/rop/</a> and this <a href="http://indiedevspot.azurewebsites.net/2015/01/20/two-track-coding-rop-for-dummies-part-2/" rel="nofollow">http://indiedevspot.azurewebsites.net/2015/01/20/two-track-coding-rop-for-dummies-part-2/</a> for reference</p>
  
  <p>I have successfully implemented this for most of the codebase, except now we are getting to putting items into SQL and wish to use ROP for validation of those types.  The typical pattern is</p>
  
  <p>Figure 1:</p>
  
  <pre><code>let createSomething a b c = {A = a; B = b; C = c}
  let createValidSomething so = 
      createSomething
      &lt;!&gt; validateFunction1 so.param1
      &lt;*&gt; validateFunction2 so.param2
      &lt;*&gt; ...so forth and so on
  </code></pre>
  
  <p>You will notice that createSomething is a function that returns a record type instantiation a -> b -> c -> a' -> b' -> c'
  The SQL Type providers return a mutable type (non record).  Lets look at my attempt to build a similar createSomething function</p>
  
  <p>Figure 2:</p>
  
  <pre><code>    let createSQS(a, b, c, d, e, f, g) =
      let sqs = context.``[dbo].[Something]``.Create(a, b, c, d, e, f, g)
      sqs
  </code></pre>
  
  <p>At this point, we know this already will not work, we have a->b->c->d->e->f->g->context.<code>[dbo].[Something]</code>.Entity</p>
  
  <p>I know I can have an intermediary record type and follow ROP principals, match on success/failure and then create my object off of the already validated.  But does that not seem like too many steps?</p>
  
  <p>Does anybody know of a good pattern for this?  Ideally we could have a function similar to Figure1 that generates a Record Type that is compatible with the Type Providers.</p>
  
  <p>I'm open to trying things and hanging out on Skype :).</p>