Ef6: "Sequence contains no matching element" message when generating migration for derived class

Created on 22 Aug 2018  路  2Comments  路  Source: dotnet/ef6

I will explain using code from solution that I develop.

I have class TextTranslation:
```c#
public class TextTranslation
{
public Guid TextTranslationId { get; set; }

    public string Name { get; set; }
    public string Text { get; set; }


    public Guid LanguageId { get; set; }
    public Language Language { get; set; }
}
I generated migration for **TextTranslation**.

Then I declared two classes **Page** and **PageTextTranslation**:

```c#
    public class Page
    {
        public Guid PageId { get; set; }
        public string Name { get; set; }

        public List<PageTextTranslation> TextTranslations { get; set; }
    } 

    public class PageTextTranslation : TextTranslation
    {
        //public Guid PageTextTranslationId { get; set; }

        //public string Name { get; set; }
        //public string Text { get; set; }

        //public Guid LanguageId { get; set; }
        //public Language Language { get; set; }

        public Guid PageId { get; set; }
        public Page Page { get; set; }
    } 

When I generate new migration for those classes I get message "Sequence contains no matching element".
When I comment inheritance for class PageTextTranslation from TextTranslation and uncomment lines, then migration generation is okay.

Further technical details

EF version: 6.2
Database Provider: EntityFramework.SqlServer
Operating system: Windows 10 Pro 1803
IDE: Visual Studio 2017 15.7

type-bug

All 2 comments

In the simple solution this works, but when you have more relations, then EF generates error.

This happens because of indexes:

```c#
modelBuilder.Entity()
.Property(tt => tt.Name)
.HasMaxLength(450);

modelBuilder.Entity()
.HasIndex(tt => tt.Name)
.HasName("IX_TextTranslations_Name");

modelBuilder.Entity()
.HasIndex(tt => tt.LanguageId)
.HasName("IX_TextTranslations_LanguageId");
```

If I remove indexes declaration the migration generation is okay, but I do need this indexes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joelmdev picture joelmdev  路  5Comments

PhilPJL picture PhilPJL  路  7Comments

Elufimov picture Elufimov  路  7Comments

Colorfulmoose picture Colorfulmoose  路  4Comments

AnReZa picture AnReZa  路  4Comments