实体框架派生的dbContext配置异常

时间:2014-05-23 08:41:12

标签: entity-framework exception dbcontext derived

我制作了一个包含在ASP(MVC)项目中的DLL,在DLL中有一些' base'功能和当前,我将其包含在其他MVC项目中。 问题是我现在有一个EF-Code第一个项目,它使用Configuration类进行迁移:

internal sealed class Configuration : DbMigrationsConfiguration<Project.Models.DbContextTest>
    {
        public Configuration()
        {
            //AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(Project.Models.DbContextTest context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }

    }

当我使用此配置时,我得到以下异常:

Sequence contains more than one matching element

关于以下功能:

return orderBy != null ? orderBy(query).ToList() : query.ToList();

该功能不是问题,因为当我删除配置类时,一切正常。 在我得到表的列表的查询中抛出异常,它只有一个主键而没有相关的表(外键)。

配置类是空的,所以我想知道它为打破我的Dll做了什么?

提前致谢, 斯蒂芬

1 个答案:

答案 0 :(得分:0)

这是启动项目和手动迁移的组合。 启动项目时,它会自动迁移代码优先模型,这与手动迁移相结合会产生此错误/异常。