using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using _Istudnet.Helper;
namespace _Istudnet.Models
{
public class Student
{
[Key]
public int Id { get; set; }
[mycustomeValidation(text:"Incadea")]
public string Name { get; set; }
public string Description { get; set; }
public string Email { get; set; }
public IFormFile simg { get; set; }
}
}
Error : The property 'Student.simg' is of an interface type ('IFormFile'). If it is a navigation, manually configure the relationship for this property by casting it to a mapped entity type. Otherwise, ignore the property using the [NotMapped] attribute or 'Ignore' in 'OnModelCreating'.
If you want to store an image, you should use a byte array type:
public byte[] Simg { get; set; }
Now, when you read your IFormFile
you can add it to your entity like so:
var file = request.FormFileFromSomewhere
using var ms = new MemoryStream();
file.CopyTo(ms);
myStudent.Simg = ms.ToArray();