Sto creando un esempio di asp.net mvc4. In questo ho creato la colonna Id come GUID nella tabella Sample di datacontext.Come impostare NewId() per GUID nell'entità framework
public class Sample
{
[Required]
public Guid ID { get; set; }
[Required]
public string FirstName { get; set; }
}
Questo è tabella di entità
CreateTable(
"dbo.Samples",
c => new
{
ID = c.Guid(nullable: false),
FirstName = c.String(nullable: false)
})
.PrimaryKey(t => t.ID);
Id passare 00000000-0000-0000-0000-000000000000.
Come impostare newid()
a GUID
e dove devo impostare.
Sei sicuro che si desidera utilizzare un GUID come chiave primaria, si verificheranno problemi di prestazioni importanti a causa della frammentazione se il GUID è l'indice cluster. –
sì voglio GUID come chiave primaria per qualche motivo. Come impostare il valore predefinito per GUId.Please help me. – user2285613
Guid.NewGuid(); –