0

My sql table has two columns that needs identity generated.

1) ID //its identity seeds trwo, identity(1,1)

2) pGuid //newid() as default values

Problem is when insert entry from UI then, it works for ID and not for pGuid field.

using entity framework, fluent API.

mapping added as

'this.property("pGuid").HasColumn("pGuid");`

what is missing with mapping and so, its not working.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3711357
  • 1,425
  • 7
  • 32
  • 54

1 Answers1

0

You can create the table with pGuid column as 'uniqueidentifier' datatype with default value as newid() as shown below, then if you insert value using EF to other columns (e.g. Company) in below table, identity and newid() values will be automatically inserted in the new row for ID and pGuid columns.

CREATE TABLE MyTable  
(  
ID INT IDENTITY(1,1) PRIMARY KEY,
 pGuid uniqueidentifier NOT NULL DEFAULT newid(),  
 Company varchar(30) NOT NULL,
..........
)
Vijai
  • 2,369
  • 3
  • 25
  • 32