Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
it-copilot4 opened this issue May 12, 2024 · 7 comments

Comments

@it-copilot4
Copy link

it-copilot4 commented May 12, 2024

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));

@it-copilot4
Copy link
Author

@paillave is this a bug of SaveMode.SqlServerBulk

@Mourad57
Copy link

Hello,

for me its not saving at all when specifying SaveMode.SqlServerBulk
It does with the other mode.

Im using the latest prerelease version.

@paillave Is this project abandoned or are you lacking help spomehow to make it progress ??

@paillave
Copy link
Owner

Hello, the project is not abandoned at all. I'm making essential maintenance for the moment. I'm planning a big chunk of essential changes for a version 3.0.
The bulksave mode is by default you don't need to mention it explicitly.
What is the result that is returned by the ExecuteAsync method?
If it fails, you should have every information about the failure. Checking the result is documented on the website.

@Mourad57
Copy link

Hi, good to know, waiting for 3.0 to come soon !

For me, it simply returns without issues/errors when bulk mode is specified.
But no data is saved. It does save when specifying the other mode.

@Mourad57
Copy link

Mourad57 commented Jul 7, 2024

Hi Steph,

there seem to be a package conflict when using etl.net from a .net 8 solution targeting microsoft.entityframeworkcore 8.0.6

thats the error

Method not found: 'System.Nullable`1<Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier> Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier.Create(Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType, Microsoft.EntityFrameworkCore.Metadata.StoreObjectType)'.

migrating etl.net to .net 8 and using latest versions of the above fixes it.

bulk saving works flawlessly after that

@paillave
Copy link
Owner

paillave commented Jul 8, 2024 via email

@it-copilot4
Copy link
Author

Hello, the project is not abandoned at all. I'm making essential maintenance for the moment. I'm planning a big chunk of essential changes for a version 3.0. The bulksave mode is by default you don't need to mention it explicitly. What is the result that is returned by the ExecuteAsync method? If it fails, you should have every information about the failure. Checking the result is documented on the website.

I tryed many times. the result always faild and return error information belowe(I use .net 8 and 7.18 EFCore,it seems the EF Save don't support GUID Primary Key):
Error occurred in node save Meituan_User(type EfCoreSave): Unhandled exception: One or more errors occurred. (Value cannot be null. (Parameter 'entityType'))
Value cannot be null. (Parameter 'entityType')
(exception: System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'entityType'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants