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

    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}")]
        public double Size { get; set; }

        public string Type { get; set; }

        public string Alt { get; set; }

        public HttpPostedFileBase File { get; set; }

        public byte[] Data { get; set; }

        public string Base64String { get; set; }

        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