Skip to content

Bug--When I save an entity with a primary key of guid to the database using the EfCoreSave method, an error occurs, prompting me to "Cannot insert value NULL into column 'Id', table 'SimpleTutorial. dbo. Author'; columns do not allow null values. UPDATE fails." When I change the insertion mode to SaveMode.EntityFrameworkCore Successfully save  #483

@it-copilot4

Description

@it-copilot4

1

Example Code
public class Author
{
public Guid Id { get; set; }
public string Email { get; set; }
public string Name { get; set; }

}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var authorBuilder = modelBuilder.Entity();
authorBuilder.ToTable(nameof(Author));
authorBuilder.HasKey(i => i.Id);
authorBuilder.HasIndex(i => i.Email).IsUnique();
authorBuilder.Property(i => i.Id).HasDefaultValueSql("NEWID()");
authorBuilder.Property(i => i.Name).IsRequired();
authorBuilder.Property(i => i.Email).HasMaxLength(250).IsRequired();

}
var authorStream = rowStream
.Distinct("remove author duplicates based on emails", i => i.Author)
// .Select("create author instance", i => new Author { Email = i.Email, Name = i.Author })
.EfCoreSave("save authors", o => o
.Entity(i => new Author {Id=Guid.NewGuid(), Email = i.Email, Name = i.Author })
.SeekOn(i => i.Name)
//.AlternativelySeekOn(i => i.Name)
.WithMode(SaveMode.SqlServerBulk));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions