0

I have a problem with "Add-Migration" instruction when the Table definition is in a new DbContext Class.

I created a new ASP.NET MVC 4 Application in Visual Studio 2012.

I ran the "Enable-Migrations", "Add-Migration mig1", "Update-Database". Everything was smooth.

Than, I added a new class inheriting the DbContext to the Models folder. I was hoping that "Add-Migration mig2" will notice the new table definition. But it does not.

Any ideas why?

namespace MvcApplication4.Models
{
    public class CmsContext: DbContext
    {
        public CmsContext()
            : base("DefaultConnection")
        {
        }

        public DbSet<CustomItem> CustomItems { get; set; }
    }

    [Table("CustomItems")]
    public class CustomItem
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        public int Ordinal { get; set; }
        public String Title { get; set; }
        public String Content { get; set; }
        public String FilePath { get; set; }
    }

}
2
  • Have you tried Enable-Migrations -ContextTypeName {NameOfTheContextType}? I think at the moment migrations are enabled only for the first context and since there is no changes to this class nothing is happening. btw. I believe that multi-tenancy is really supported in EF6 and not in EF5 (see: entityframework.codeplex.com/…) Commented Jul 9, 2013 at 21:52
  • Pawel - Thank you very much. Indeed EF5 "Enable-Migrations" can work only one context at a time. Following your instructions, the complete command is "Enable-Migrations -ContextTypeName {xyz} -Force". Running the command "Enable-Migrations -Force" (without the specific context name) will result the console error: "More than one context type was found in the assembly...". Another relevant SO thread can be found here: link Commented Jul 10, 2013 at 7:40

1 Answer 1

1

Multi-tenancy is not supported in EF5 but is supported in EF6 where you can specify a context for which you want to enable migrations for like this:

Enable-Migrations -ContextTypeName {NameOfTheContextType}

See the migrations multi-tenancy feature spec on the Entity Framework codeplex site.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.