Ejemplo n.º 1
0
        public void StoreDrive()
        {
            int i = 1;
            List <tDirectory> tDirectories = new List <tDirectory>();

            foreach (var d in drives)
            {
                tDirectory tDirClient = new tDirectory();
                tDirClient.Directory   = d.Name.Trim();
                tDirClient.DirectoryId = i;
                i++;
                tDirectories.Add(tDirClient);
            }
            using (var filesDbContext = new FilesDBContext())
            {
                try
                {
                    foreach (var item in tDirectories)
                    {
                        filesDbContext.tDirectories.Add(item);
                        filesDbContext.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 读取存入的数据
 /// </summary>
 public override void GetResult()
 {
     using (var filesDbContext = new FilesDBContext())
     {
         var drives = from d in filesDbContext.tDirectories
                      select d;
         foreach (var d in drives)
         {
             Console.WriteLine("{0} id is {1}", d.Directory.Trim(), d.DirectoryId);
         }
     }
 }