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);

5
  • An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code Commented May 26, 2014 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. Commented May 26, 2014 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. Commented May 26, 2014 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. Commented May 27, 2014 at 7:31
  • I store images in db like this : stackoverflow.com/a/17969875/1814343 Commented Aug 10, 2014 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.