sensei
sensei

Reputation: 7562

Entity Framework doesn't implement interface member for View

I created a view and added it to my Model via "Update model from database". Model validates, but as soon as I add that new View into Interface, it throws error on compile:

Error 4 'Entities.Model.TestEntities' does not implement interface member 'Entities.Interfaces.ITestEntities.CustomerWinningsView'

Which is very interesting, since when I add normal table member it works with no problems.

public interface ITestEntities
{
DbSet<Browser> Browsers { get; set; } - normal table works
DbSet<CustomerWinningsView> CustomerWinningsView { get; set; } - view throws error on compile..
}

Context:

public partial class TestEntities : DbContext, ITestEntities
{
    public TestEntities()
        : base("name=TestEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public DbSet<Browser> Browsers { get; set; }
    public DbSet<CustomerWinningsView> CustomerWinningsViews { get; set; }
}

Do I have to set something additional for views in EF?

Upvotes: 0

Views: 1522

Answers (1)

StuartLC
StuartLC

Reputation: 107317

Your interface defines

DbSet<CustomerWinningsView> CustomerWinningsView { get; set; } 

Yet your DbContext implements

public DbSet<CustomerWinningsView> CustomerWinningsViews { get; set; }

Change either interface or implementation method to match eachother. (CustomerWinningsView or CustomerWinningsViews). If as you say both were code generated, it might be a bug in the pluralization mechanism.

Upvotes: 2

Related Questions