D
D
Dmitry Gavrilenko2016-10-30 23:23:58
.NET
Dmitry Gavrilenko, 2016-10-30 23:23:58

Why doesn't EF populate the value?

ASP Core project with EF Core.
In Context Code

modelBuilder.Entity<Table>(option => {
                option.Property(p => p.Guid)
                .ValueGeneratedOnAdd()
                .IsRequired();
            });

that is in the field Guid value.
It doesn't work, writes cannot insert the value null into column Guid
Ok. I put the attribute [DatabaseGenerated(DatabaseGeneratedOption.Identity)] to the field in the model.
cannot insert the value null into column Guid
Ok.
var newTable = new Table()
newTable.Guid = new Guid();
context.MyTables.Add(newTable);
context.SaveChanges();

cannot insert the value null into column Guid

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-10-31
@Maddox

In the third example, new Guid()use - instead Guid.NewGuid()- the default constructor always returns a null GUID.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question