Net Core 2.0 Entity Framework. When I try to insert data using _context.UserTask.AddRange(userTasks)
, the TaskID
is not being updated after invoking SaveChanges()
. Below is the code I'm using.
public partial class UserTask
{
public Guid TaskID { get; set; }
public string Text{get;set;}
}
var tasks = taskTexts.Select(s => new UserTask { Text="abc" });
_context.UserTask.AddRange(tasks);
await _context.SaveChangesAsync();
foreach(var n in notifications){
n.TaskID //This is not returning the actualID inserted on the DB
}
Below is the Table structure
CREATE TABLE dbo.Task(
TaskID [uniqueidentifier] NOT NULL,
[Text] [varchar](200) NOT NULL
CONSTRAINT [PK_TaskID] PRIMARY KEY CLUSTERED
(
TaskID ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE dbo.Task ADD CONSTRAINT [DF_TaskID] DEFAULT (newsequentialid())
FOR [TaskID]
GO