-
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
NullReferenceException when trying to seed a keyless entity #23030 #23562
Conversation
InMemoryTable depends on Key Model name Seed instead KeylessSeed
SqlServer & SqlLite tests passed but InMemory couldn't because its depend on CreateFactory has key. private Func<IInMemoryTable> CreateTable([NotNull] IEntityType entityType, IInMemoryTable baseTable)
=> (Func<IInMemoryTable>)typeof(InMemoryTableFactory).GetTypeInfo()
.GetDeclaredMethod(nameof(CreateFactory))
.MakeGenericMethod(entityType.FindPrimaryKey().GetKeyType())
.Invoke(null, new object[] { entityType, baseTable, _sensitiveLoggingEnabled, _nullabilityCheckEnabled });
[UsedImplicitly]
private static Func<IInMemoryTable> CreateFactory<TKey>(
IEntityType entityType,
IInMemoryTable baseTable,
bool sensitiveLoggingEnabled,
bool nullabilityCheckEnabled)
=> () => new InMemoryTable<TKey>(entityType, baseTable, sensitiveLoggingEnabled, nullabilityCheckEnabled); |
@umitkavala This does not look like the correct fix. The comment from Smit in #23030 says:
This means the correct resolution for this bug is to throw an InvalidOperationException with a message indicating that seeding keyless entity types are not supported. |
@ajcvickers Sure. I'll implement that way. I couldn't make sure that's why I've created as draft. And this rule apply for all right? SqlServer, InMemory, SqlLite. So in that case test I can add test case to the SeedingTestBase.cs |
@umitkavala Sounds good. |
Unit test updated and moved to SeedingTestBase
I did required changes. |
Tests were failing when run all. Changed DB name for keyless tests.
Can I convert this draft to PR for final review? |
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
…fcore into seed-keyless-entity
make sure EnsureClean execute first.
Hi @AndriySvyryd, I think this PR is ready. |
protected abstract SeedingContext CreateContextWithEmptyDatabase(string testId); | ||
|
||
protected abstract KeylessSeedingContext CreateKeylessContextWithEmptyDatabase(string testId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected abstract KeylessSeedingContext CreateKeylessContextWithEmptyDatabase(string testId); | |
protected virtual KeylessSeedingContext CreateKeylessContextWithEmptyDatabase() | |
=> new KeylessSeedingContext(TestStore.AddProviderOptions(new DbContextOptionsBuilder()).Options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeylessSeedingContext won't be abstract anymore and we won't need KeylessSeedingContext implementations on other classes (KeylessSeedingSqlServerContext, KeylessSeedingSqliteContext, KeylessSeedingInMemoryContext)
public class KeylessSeedingContext : DbContext
{
public KeylessSeedingContext(DbContextOptions options)
: base(options)
{
}
Other implementations removed : KeylessSeedingSqlServerContext, KeylessSeedingSqliteContext, KeylessSeedingInMemoryContext
Thanks for your contribution |
Thanks. |
Fixes #23030
I'm not sure about tests. Is it enough or correct place? I've changed base class so implemented classes also should change.
Maybe we can create new test class?