i get error when save with _db.bulksavechange();
Description
i get error when save with _db.bulksavechange();
var newBrand = new Brand
{
Name = brand.Name,
Memo = brand.Memo,
IsSystemValue = false,
CreatedBy = DefaultFuntion.GetCurrentUserId(),
CreatedDate = DefaultFuntion.GetCurrentDateTime(),
Version = 1,
StatusId = brand.StatusId
};
_db.Brands.Add(newBrand);
newBrand.Photo = DefaultFuntion.ResizeImage(150M, 150M, photo);
var newPhotoAndVideo = new PhotoAndVideo
{
FileName = fileName.Split('.').FirstOrDefault(),
SortOrder = 0,
};
newBrand.PhotoAndVideos.Add(newPhotoAndVideo);
_db.BulkSaveChanges(operation => operation.BatchTimeout = 3600000);
Exception
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:
The MERGE statement conflicted with the FOREIGN KEY constraint "FK_ItemPhoto_Brand".
The conflict occurred in database "EasyAccounting_523", table "dbo.Brand", column 'Id'.
Stack trace:
``` at DbContextExtensions.(DbContext this, Boolean , Action`1 , Boolean )
at DbContextExtensions.BulkSaveChanges(DbContext this, Action`1 bulkOperationFactory)
at SmartInventory.Controllers.BrandController.Create(BrandCustomModel brand) in
D:\Chuo Vechet\Easy Accounting - Development V5.3.2\Easy Accounting - Development\SmartInventory\Controllers\BrandController.cs:line 133
Hello @vechet ,
Is SaveChanges working with this scenario?
If yes, could you provide your Entity Type class and model mapping to allow us to reproduce this scenario? Your case seems pretty simple.
You can send your code here [email protected] if you want to keep them private.
Best Regards,
Jon
Hello @JonathanMagnan yes it work with SaveChanges
i ues entity framework 5 with model that generate from edmx . how can i fix this error ? please help.
Could you send a small runnable project here: [email protected]
It will be way faster for us to look at it with a project.
Hello @JonathanMagnan
yes, you can download a small runnable project from google drive url here :
https://drive.google.com/file/d/1uKZPi2-Byr-KqHF4Rl8wtgmE1mLqmhvj/view?usp=sharing
Thank you for the project, we can now successfully reproducing it.
Unfortunately, I cannot guarantee yet if we could fix it as we don't support in Entity Framework 5 as much as we do in EF6 or EF Core. For example, the whole identity propagation (which is the error here) has been re-written in our code starting from EF6 but we never bring it back the code in EF5 since it was too much complicated.
We will see if there is still something we can do here.
thanks for your help. can i know which version EF5 that you reproducing to solve above problem.
so, about EF6 have this problem or not?
Hello @vechet ,
In EF6, the BulkSaveChanges() doesn't have anymore this issue.
However, if you remove the DefaultEntityFrameworkPropagationValue (https://entityframework-extensions.net/improve-bulk-savechanges), you will likely get it back since when disabled, the same code as EF5 is used.
can i know which version EF5 that you reproducing to solve above problem
I'm not sure to understand this question. There is only one version of EF5 released on NuGet: https://www.nuget.org/packages/EntityFramework/5.0.0