title: Entity Framework 6 and SQL Server Sequences
body: <p>I am using EF6 with a database first project. We have a requirement to use sequences which was a feature introduced in SQL server 2012 (I believe).</p>
  
  <p>On the table the identity column has a default value set using:</p>
  
  <pre><code>(NEXT VALUE FOR [ExhibitIdentity])
  </code></pre>
  
  <p>This is used as we have two tables which store exhibit information for separate departments but we need the identity to be unique across both of the tables as it is then used as a reference in lots of other shared common tables.</p>
  
  <p>My problem is using this within the Entity Framework, I have googled but couldn't find much information in relation to whether EF6 supports them. I have tried setting <code>StoreGeneratedPatttern</code> in the <code>EFdesigner</code> to <em>Identity</em> but when saving this complains that zero rows were affected as it is using <code>scope_identity</code> to see if the insert succeeded but as we are using sequences this comes back as null.</p>
  
  <p>Setting it to <em>computed</em> throws an error saying I should set it to identity and setting it to none causes it to insert 0 as the id value and fail.</p>
  
  <p>Do I need to call a function/procedure in order to get the next sequence and then assign it to the id value before saving the record?</p>
  
  <p>Any help is much appreciated.</p>