Exemplo n.º 1
0
 public void Add(person person)
 {
     using (var db = new personrepositoryEntities())
     {
         try
         {
             db.persons.Add(person);
             db.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             throw;
         }
     }
 }
Exemplo n.º 2
0
 public void Update(person person)
 {
     using (var db = new personrepositoryEntities())
     {
         try
         {
             db.persons.Attach(person);
             db.Entry(person).State = System.Data.Entity.EntityState.Modified;
             var count = db.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             throw;
         }
     }
 }
Exemplo n.º 3
0
 public void UpdatePersonTag(string faceId, string[] tags)
 {
     using (var db = new personrepositoryEntities())
     {
         var haveTags = db.persontags.Where(s => s.FaceID == faceId).Select(s => s.TagName).ToArray();
         var newTags  = tags.Except(haveTags).ToArray();
         foreach (var tag in newTags)
         {
             persontag pt = new Repository.persontag()
             {
                 FaceID  = faceId,
                 TagName = tag
             };
             db.persontags.Add(pt);
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void AddPersonTag(string faceId, string[] tags)
 {
     using (var db = new personrepositoryEntities())
     {
         //删除旧标签
         var sql   = "delete from persontags where faceid='" + faceId + "'";
         var count = db.Database.ExecuteSqlCommand(sql);
         print("删除旧标签->" + count);
         foreach (var tag in tags)
         {
             persontag pt = new Repository.persontag()
             {
                 FaceID  = faceId,
                 TagName = tag
             };
             db.persontags.Add(pt);
         }
         db.SaveChanges();
     }
 }