19 Kasım 2016 Cumartesi

HttpPostedFileBase mapping error at Entitiy Framework




'HttpPostedFileBases: EntityType: EntitySet 'HttpPostedFileBases' is based on type 'HttpPostedFileBase' that has no keys defined.'

This error comes with object by HttpPostedFileBase class.I am using that type to perform my processes about image files.There is sample an image class below :

  public enum UsageType
    {
        Logo,
        Profil
    }

    public class Image : BaseObject
    {
        public const int MAX_IMG_SIZE = 3072;
        public static readonly string[] ALLOWED_IMG_TYPES = { "image/jpeg", "image/png" };

        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
        [ReadOnly(true)]
        [DisplayName("Size")]
        public double Size { get; set; }

        [ReadOnly(true)]
        [DisplayName("Type")]
        public string Type { get; set; }

        [Required]
        [DisplayName("Alt")]
        public string Alt { get; set; }

        [Required]
        [DisplayName("File")]
        [NotMapped]
        public HttpPostedFileBase File { get; set; }

        [DisplayName("Data")]
        public byte[] Data { get; set; }

        [DisplayName("Base64")]
        public string Base64String { get; set; }

        [DisplayName("Src")]
        public string Src { get; set; }

        [DisplayName("Usage Type")]
        public UsageType UsageType { get; set; }
........................

Solution : In Entitiy Framework when you update your schema the error appears on package manager console which is I have mentioned above.You need HttpPostedFileBase object to catch image file.For that reason just type that annotation inside the code below colored blue(Not Mapped).After that migration system wont try to convert this File property to a database column.We use file object to fill other fields of our class such as size,data.etc.




Hiç yorum yok:

Yorum Gönder