concept default constraint in category entity framework

appears as: default constraint
Entity Framework Core in Action

This is an excerpt from Manning's book Entity Framework Core in Action.

The SQL code that EF Core produces, if it’s asked to create/migrate an SQL Server database, looks like the following SQL snippet, with the default constraint in bold:

CREATE TABLE [Defaults] (
    [Id] int NOT NULL IDENTITY,
    -- other columns left out
    [DateOfBirth] datetime2 NOT NULL 
            DEFAULT '2000-01-01T00:00:00.000',
    CONSTRAINT [PK_Defaults] PRIMARY KEY ([Id])
);



!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":4,\"ch\":12},{\"line\":4,\"ch\":46}]]"}
!@%STYLE%@!

If the column in a new entity has the CLR default value, EF Core doesn’t provide a value for that column in the SQL INSERT, which means the database server will apply the default constraint of the column definition to provide a value to insert in the new row.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest