0

I have following database schema and I would like to seed the data in the database but I could not understand how to seed the images at first go, what should be in the table entity.

first code snippedsecond code snippetthird code snippet

I need help to know where I need changes.

Thanks.

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
Urgen
  • 1,095
  • 3
  • 19
  • 39

1 Answers1

1

Since you referenced Core, here's the easiest way (in Program.Main)

try
{
    var host = BuildWebHost(args);

    using (var scope = host.Services.CreateScope())
    {
        var services = scope.ServiceProvider;
        try
        {
            var context = services.GetRequiredService<myContext>();
            DbInitializer.Seed(context);
        }
        catch
        {
            throw;
        }
    }

    host.Run();
}
catch
{
    throw;
}

and create a class called DbInitializer with a method Seed that takes an EF context. I think you can take it from there.

(and don't post images of code, post the code using Ctrl+K to format code-blocks)

John White
  • 705
  • 4
  • 12
  • Thanks for the reply but you did not seem to get my point. I can seed the data other than images. If you refer my code snippets. I have no problems seeding data other than images, which are located in the wwwroot/img folder. I just want my images to be seeded in the database like other data.. – Urgen Jun 11 '18 at 20:07
  • I supplied how to implement database seeding using Core and EF-Core. Inside the Seed method is where you acquire the data you wish to seed in your database. Now, if you are unfamiliar with how to load an image into a byte[] array, try this https://stackoverflow.com/questions/3801275/how-to-convert-image-to-byte-array – John White Jun 20 '18 at 20:21