private void SaveProductImage(string file) { var splitedName = file.Split('.'); var extension = splitedName[splitedName.Length - 1]; var stream = File.OpenRead(file); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); using (ProductDataContext db = new ProductDataContext("StoreAppB")) { var product = db.Set <Product>().Find(int.Parse(ProductIDTxt.Text)); ProductImage pi = new ProductImage { ImageData = buffer, ImageMimeType = extension, SequenceNumber = short.Parse(SequenceNumber.Text), Product = product }; db.Set <ProductImage>().Add(pi); db.SaveChanges(); } }