Skip to content

EF Core 6 Views with navigation property throw exception when using CompareEfWithDb #21

@benwts

Description

@benwts

I am running CompareEfWithDb to compare my existing database with entities.
I will get an error on the log output, and it stops comparing the rest of the entities.

E.g. All my views prefix "Vw", so any entity's name started after V is not compared.

Below is an example of a View with navigation properties.

public class Blog
{
    public int BlogId { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
}

public class VwBlogPosts
{
    public int BlogId { get; set; }
    public int PostId { get; set; }
    public string BlogName { get; set; }
    public string PostTitle { get; set; }

    public virtual Blog Blog { get; set; }
    public virtual Post Post { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder
        .Entity<VwBlogPosts>(
            eb =>
            {
                eb.HasNoKey();
                eb.ToView("VW_BlogPosts");
                eb.HasOne(t => t.Blog).WithMany().HasForeignKey(t => t.BlogId);
                eb.HasOne(t => t.Post ).WithMany().HasForeignKey(t => t.PostId);
            });
}

----> System.ArgumentNullException : Value cannot be null. (Parameter 'key')

Stack Trace:  DummyTestFixture.CompareViaContext() line 58 --ArgumentNullException Dictionary``2.FindValue(TKey key) Stage1Comparer.CompareForeignKeys(CompareLog log, IEntityType entityType, DatabaseTable table) Stage1Comparer.CompareModelToDatabase(DatabaseModel databaseModel) CompareEfSql.FinishRestOfCompare(String connectionString, DbContext[] dbContexts, IDesignTimeServices designTimeService) CompareEfSql.CompareEfWithDb(String configOrConnectionString, DbContext[] dbContexts) CompareEfSql.CompareEfWithDb(DbContext[] dbContexts) DummyTestFixture.CompareViaContext() line 48

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