Reputation: 181
I'm trying to scaffold a controller for the following model for EF but I'm receiving:
Unable to retrieve metadata for 'Project.Models.ItemModel'.
Value cannot be null.
Parameter name: entitySet'
Is it trying to retrieve something from somewhere but cant?
ItemModel
public class ItemModel
{
public class ItemPicture
{
[Key, ForeignKey("ItemModel")]
public virtual int ItemID {get;set;}
public HttpPostedFileBase Image { get; set; }
public virtual ItemModel ItemModel { get; set; }
}
[Key]
public int ItemID { get; set; }
[Required(ErrorMessage ="{0} is required.")]
[Display(Name ="Item Name")]
public string ItemName { get; set; }
[Required(ErrorMessage = "{0} is required.")]
[Display(Name = "Item Description")]
[DataType(DataType.MultilineText)]
public string ItemDesc { get; set; }
[Required(ErrorMessage = "{0} is required.")]
[Display(Name = "Item Price")]
public decimal ItemPrice { get; set; }
public virtual ItemPicture Picture { get; set; }
[Required(ErrorMessage = "{0} is required.")]
[Display(Name = "Enable Front Feature")]
public bool FrontFeature { get; set; }
}
Upvotes: 2
Views: 335
Reputation: 1742
Tried it myself... don't think you should store HttpPostedFileBase as a property of your model, well at least not map it via EntityFramework and let it automatically scaffold. If you think about it - what database fields do you think this property type would map to?
If you want to actually store the binary data in your database, use the following:
public byte[] File { get; set; }
Upvotes: 1