EF 4.1 SeedData no se completa la tabla

I have created a SeedData class, and populated it with the values that I would like to be populated into the table. When I run the application, I am not getting any errors, but the table is not populating with the Seed Data.

I am using ASP.NET MVC3 and EF 4.1

I have tried both DropCreateDatabaseAlways and DropCreateIfModelChanges with no luck

In the Global ASAX I have the following link in Application_Start

System.Data.Entity.Database.SetInitializer(new EDWv2.Models.SeedData());

My SeedData class is define as follows:

public class SeedData : DropCreateDatabaseAlways<EDWContext>
{
    protected override void Seed(EDWContext context)
    {

        var controlsystemdesignation = new List<ControlSystemDesignation>
        {
            new ControlSystemDesignation { Name = "BA"},
            new ControlSystemDesignation { Name = "BP"},
            new ControlSystemDesignation { Name = "RA"},
            new ControlSystemDesignation { Name = "GA"},
            new ControlSystemDesignation { Name = "WA"},
            new ControlSystemDesignation { Name = "WB"},
            new ControlSystemDesignation { Name = "WC"},
            new ControlSystemDesignation { Name = "EA"},
            new ControlSystemDesignation { Name = "EB"},
            new ControlSystemDesignation { Name = "EC"},
            new ControlSystemDesignation { Name = "DA"},
            new ControlSystemDesignation { Name = "DB"},
            new ControlSystemDesignation { Name = "DC"},
            new ControlSystemDesignation { Name = "FA"},
            new ControlSystemDesignation { Name = "FB"},
            new ControlSystemDesignation { Name = "SA"},
            new ControlSystemDesignation { Name = "SB"},
            new ControlSystemDesignation { Name = "SC"},
            new ControlSystemDesignation { Name = "LA"},
            new ControlSystemDesignation { Name = "LD"},
            new ControlSystemDesignation { Name = "DP"},
            new ControlSystemDesignation { Name = "PA"},
            new ControlSystemDesignation { Name = "PB"},
            new ControlSystemDesignation { Name = "PC"},
            new ControlSystemDesignation { Name = "UL"},
            new ControlSystemDesignation { Name = "UA"}
    };
        base.Seed(context);
        context.SaveChanges();
    }
}

Gracias,

Jason

preguntado el 30 de enero de 12 a las 19:01

2 Respuestas

Necesitas agregar ControlSystemDesignation entidades para context.

public class SeedData : DropCreateDatabaseAlways<EDWContext>
{
    protected override void Seed(EDWContext context)
    {

        var controlsystemdesignation = new List<ControlSystemDesignation>
        {
            new ControlSystemDesignation { Name = "BA"},
            new ControlSystemDesignation { Name = "BP"},
            new ControlSystemDesignation { Name = "RA"},
            new ControlSystemDesignation { Name = "GA"}
            //...
        };

        controlsystemdesignation.ForEach(item => context.ControlSystemDesignations.Add(item));

        context.SaveChanges();
    }
}

Respondido el 31 de enero de 12 a las 01:01

thank you for the tip, it helped me to get the data populated. - Jason

You'll need to add those instances to a DbSet<ControlSystemDesignation>, which should be part of your context.

context.ControlSystemDesignations.Add(instance);

Respondido el 31 de enero de 12 a las 01:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.