コード例 #1
0
        public int InsertSingleImageFile(string filePath)
        {
            int       startIndexOfFilename = filePath.LastIndexOf('\\') + 1;
            string    fileName             = filePath.Substring(startIndexOfFilename);
            ImageFile imageFile            = new ImageFile();

            imageFile.FilePath = filePath;
            imageFile.FileName = fileName;

            try
            {
                using (var db = new SourceDBContext())
                {
                    db.imageFiles.InsertOnSubmit(imageFile);
                    db.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                Console.WriteLine("Cannot Insert " + fileName + " Into database. " +
                                  "Most likely is a violation of unique key constraint " +
                                  "because the file allready exisits in the database");
            }
            return(0);
        }
コード例 #2
0
 public ImageFile InsertImageFile(ImageFile imageFile)
 {
     using (var db = new SourceDBContext())
     {
         db.imageFiles.InsertOnSubmit(imageFile);
         db.SubmitChanges();
     }
     return(imageFile);
 }