0
   [HttpPost]
   public void Test(HttpPostedFileBase file)
   {
       UsersContext db = new UsersContext();

       byte[] image = new byte[file.ContentLength];

       file.InputStream.Read(image, 0, image.Length);

       CrimeReport i = new CrimeReport 

       { 
       ImageId=1, ImageName="Ali",ImageContent = image,
       Active=true
       };
       db.CrimeReports.Add(i);

       db.SaveChanges();
   }

I am getting an exception on db.CrimeReports.Add(i);

Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
user3532152
  • 17
  • 1
  • 9
  • An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code – user3532152 May 26 '14 at 21:24
  • This exception says that you pushing wrong data to entity framework model, also you can get it if any of mandatory properties of CrimeReport is not filled. Try to set breakpoint on db.SaveChanges() and debug it. In exception details you should see more info. – Oleksii Aza May 26 '14 at 21:31
  • is your foreign key relation is one to one relation ship? let you know One-to-one foreign key associations are not supported in EF. – PEO May 26 '14 at 21:35
  • I have added all compulsory fields of table and this table has a primary key ImageId and the other table has a foreign key ImageId. – user3532152 May 27 '14 at 07:31
  • I store images in db like this : http://stackoverflow.com/a/17969875/1814343 – Amin Saqi Aug 10 '14 at 13:15

0 Answers0