Allow SQL to generate GUID ID when inserting new row.

http://www.developerhandbook.com/entity-framework/entity-framework-use-a-guid-as-the-primary-key/

For Database First:

If you having your inserts use Guid.Empty rather then generating a new ID see the above article. Using EDMX you need to edit every ID property in the EDMX and set the “StoreGeneratedPattern” to “Identity”.

Set the database table’s Id ‘s default property¬†newsequentialid().

 

For Code First:

In code first, rather than editing the EDMX, you simply put this attribute on each of your Id fields:

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id{ get;set; }

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s