-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Seeding binary data + migration causes issues (memory + duration) #21065
Comments
@ntziolis After discussion with the team, we think using seed data for this is probably not the way to, since it's not designed for large amounts of binary data. Your workaround seems okay for now. I'm putting this on the backlog to consider making binary data more efficient here. |
Understood and totally ok with using the workaround path. In fact we would be totally ok with ef core not supporting binary data seeding at all. Just want to call out the following again:
To let others not suffer the same fate I would suggest:
|
Opened dotnet/EntityFramework.Docs#2416 to track updating the docs. |
Coming from #23118, @roji recommended me to go with custom initialization logic as per the documentation this is fine and this is something I'm trying to do now. There is one case I am unsure of how to handle though, and thats circular references. When using the |
@andrejohansson one common way is to just set the IDs yourself before saving your entities. |
@roji won´t that get me a constraint exception when saving the first entity since the second one is not saved yet (chicken and egg)? I'll try... |
@andrejohansson Typically you would use navigation properties to define relationships, as is normal with EF. If you want to use FK values explicitly, then you can, and as long as the FKs are mapped (as is normal), then EF will order the updates appropriately. |
Depending on the specific database type (and how you start your transactions), it may be possible to defer the constraint checking until the transaction is committed. Or if the table(s) are only in use by the seeding logic at that point, you can temporarily turn off constraints before seeding and reinstate afterwards. Or you can do whatever was working for you when seeding - if you were adding a new column to the table (including the constraint), that should work without seeding as well... |
Duplicate of #19710 |
We have a report template table that holds binary data which contains the templates. We included this binary data in our seed
HasData
. The total size of all templates is < 2 MByte (so really not that much). We had no issues while using drop / create so far. Recently we have moved to use migrations which is when we ran into the following issues:Steps to reproduce
HasData
to seed the entity with dataIf needed I will be providing a repo, but thought to let you guys know right away.
Further technical details
EF Core version: 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: 3.1
Operating system: Windows
IDE: VS 2019, but should not matter as dotnet cli with ef extensions were used to create migrations
Workaround
If anybody runs into this while its not fixed here is the workaround that worked for us:
HasData
callsThe text was updated successfully, but these errors were encountered: