Question

I've searched high and low for this answer but can't find anything.... am I being daft?

    protected override void Seed(MyContext context)
    {
        context.Items.Add(new Item
        {
            URL = "my-url-field",
            Title = "My Title for this Item",
            Image = "some-image-file.jpg"  // this is httppostedfilebase  - how to seed this?
        });
    }

I imagine I'd have to instantiate an object of httppostedfilebase, but how do I do this?

Was it helpful?

Solution

I think HttpPostedFileBase is the wrong property for your model. You probably want instead to have the Image property as a byte[] - this is what will be stored in the database. If you require the filename as well, you could just make that a string property on Item

Then, your seed method would look like

...
Image = File.ReadAllBytes("some-image-file.jpg"),
Filename = "some-image-file.jpg"
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top