當我開始我的MVC應用程序,這個錯誤出現UPP 「的EntityType‘HttpPostedFile’沒有定義鍵」的EntityType「HttpPostedFile」無鍵定義
有人能告訴我什麼是錯在這裏嗎?
型號:
public partial class Advert
{
[Key]
public int ID { get; set; }
[Required]
public HttpPostedFile ImageData { get; set; }
[Required]
public string UrlToUse { get; set; }
[Required]
public string Author { get; set; }
[Required]
public int SchemaType { get; set; }
public string Title { get; set; }
}
當控制器撞到,我運行這個
public ActionResult DisplayAdvert()
{
db.Database.CreateIfNotExists();
return PartialView("_Advert");
}
和吊杆,在行db.Database.CreateIfNotExists();失敗:
Boat_Club.Models.HttpPostedFile:的EntityType 'HttpPostedFile' 沒有定義鍵。定義此EntityType的關鍵字。 HttpPostedFiles:EntityType:EntitySet'HttpPostedFiles'基於沒有定義鍵的類型'HttpPostedFile'。
我搜索了一些答案,所有說我要補充[關鍵]示範,而我,所以這是怎麼回事?
我使用Visual Studio Express的2013年的Web,用MVC和EF的所有latets版本。
/謝謝
雖然這工作!
public partial class Advert
{
[Key]
public int ID { get; set; }
[Required]
public byte[] ImageData { get; set; }
[Required]
public string UrlToUse { get; set; }
[Required]
public string Author { get; set; }
[Required]
public int SchemaType { get; set; }
public string Title { get; set; }
}
謝謝!剛剛嘗試過,它的工作原理!看到在這裏的另一篇文章,使用HttpPostedFileBase,這是可能的! [SO張貼在這裏(http://stackoverflow.com/questions/8777623/how-to-upload-image-to-sql-with-mvc3-within-one-form-using-ado-net) –
不確定,但我個人仍然不會直接使用這些類型。 – Lloyd
試過HttpPostedFileBase,那裏沒有運氣。所以我要用字節[],對我來說更有意義!謝謝!! –