当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.Entry方法代码示例

本文整理汇总了C#中DataContext.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.Entry方法的具体用法?C# DataContext.Entry怎么用?C# DataContext.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.Entry方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_LockForEditing

 public void Test_LockForEditing()
 {
     try
     {
         User iUser = UsersRepository.Instance.GetAllUsers().First();
         Assert.IsNull(iUser.Lock_);
         using (DataContext testContext = new DataContext(connection))
         {
             User testUser = testContext.Users.Find(iUser.ID);
             testContext.Lock<User>(testUser);
             testContext.Entry(testUser).Reload();
             Assert.IsNotNull(testUser.Lock_);
             testContext.Unlock<User>(testUser);
             Assert.IsNull(iUser.Lock_);
         }
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }
开发者ID:George-Andras,项目名称:HomeInventories,代码行数:21,代码来源:LockingTests.cs

示例2: Attach

		/// <summary>
		/// Attaches the entity to the given context with the specified state.
		/// </summary>
		/// <param name="db">The db context</param>
		/// <param name="state">The entity state</param>
		public void Attach(DataContext db, EntityState state) {
			db.Entry(this).State = state;
		}
开发者ID:jerry-he,项目名称:Piranha,代码行数:8,代码来源:BaseEntity.cs

示例3: updateGV

 public void updateGV(int id, string value, string date, int regId, int gradeId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.GradeValues.Include("Registration").Include("Grade").Where(orig => orig.GradeValueID == id).FirstOrDefault();
             if (original != null)
             {
                 if (regId != original.Registration.RegistrationID || gradeId != original.Grade.GradeID)
                 {
                     if (isGrade(gradeId, regId))
                     {
                         MessageBox.Show("Student already have this grade value.", "GradeValue Update Error");
                         return;
                     }
                     var reg = db.Registrations.Find(regId);
                     original.Registration = reg;
                     var g = db.Grades.Find(gradeId);
                     original.Grade = g;
                 }
                 if (!string.IsNullOrEmpty(value))
                 {
                     original.Value = value.ToUpper();
                 }
                 if (!string.IsNullOrEmpty(date))
                 {
                     original.Date = date;
                 }
                 original.TimeStamp = timestamp;
                 db.GradeValues.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbUpdateException ex)
     {
         MessageBox.Show("GradeValue Update Error", "GradeValue Update Error");
         return;
     }
     catch (DbEntityValidationException e)
     {
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:50,代码来源:Storage.cs

示例4: updateRegistration

 public void updateRegistration(int id, int realId, int studId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Registrations.Include("Realisation").Include("Student").Where(o => o.RegistrationID == id).FirstOrDefault();
             if (orig != null)
             {
                 if (orig.Realisation.RealisationID != realId || orig.Student.StudentID != studId)
                 {
                     if (db.Registrations.Where(o => o.Realisation.RealisationID == realId).Where(o => o.Student.StudentID == studId).FirstOrDefault() != null)
                     {
                         MessageBox.Show("Student is already registered to this realisation.", "Realisation Update Error");
                         return;
                     }
                     else
                     {
                         var real = db.Realisations.Find(realId);
                         orig.Realisation = real;
                         var stud = db.Students.Find(studId);
                         orig.Student = stud;
                         orig.TimeStamp = timestamp;
                         db.Registrations.Attach(orig);
                         db.Entry(orig).State = EntityState.Modified;
                         db.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     {
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:40,代码来源:Storage.cs

示例5: updateGrade

 public void updateGrade(int id, string gradeName, string maxValue, int realId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Grades.Include("Realisation").Where(orig => orig.GradeID == id).FirstOrDefault();
             if (original != null)
             {
                 if (realId != original.Realisation.RealisationID)
                 {
                     var real = db.Realisations.Find(realId);
                     original.Realisation = real;
                 }
                 if (!string.IsNullOrEmpty(maxValue))
                 {
                     string Stud = string.Empty;
                     List<GradeValue> gv = db.GradeValues.Include("Grade").Include("Registration").Include("Registration.Student").Where(o => o.Grade.GradeID == id).ToList();
                     if (gv != null)
                     {
                         foreach(GradeValue v in gv)
                         {
                             if (!Validation(maxValue, v.Value))
                             {
                                 Stud = string.Concat(Stud, "\n", v.Registration.Student.LastName);
                                 Console.WriteLine(v.Registration.Student.LastName);
                             }
                         }
                         if (!string.IsNullOrEmpty(Stud))
                         {
                             MessageBox.Show("You have to change or delete these students marks:" + Stud, "Grade MaxValue Update Error");
                             return;
                         }
                     }
                     original.MaxValue = maxValue.ToUpper();
                 }
                 if (!string.IsNullOrEmpty(gradeName))
                 {
                     if (db.Grades.Include("Realisation").Where(o => o.Realisation.RealisationID == realId).Where(o => o.Name == gradeName).FirstOrDefault() != null)
                     {
                         MessageBox.Show("Grade name must be unique in realisation.", "Grade Update Error");
                         return;
                     }
                     original.Name = gradeName;
                 }
                 original.TimeStamp = timestamp;
                 db.Grades.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbUpdateException ex)
     {
         MessageBox.Show("Grade Update Error", "Grade Update Error");
         return;
     }
     catch (DbEntityValidationException e)
     {
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:66,代码来源:Storage.cs

示例6: updateRealisation

 public void updateRealisation(int id, int semId, int subId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Realisations.Include("Subject").Include("Semester").Where(o => o.RealisationID == id).FirstOrDefault();
             if (orig != null)
             {
                 if (orig.Semester.SemesterID != semId || orig.Subject.SubjectID != subId) //jeśli coś się zmieniło
                 {
                     if (db.Realisations.Where(o => o.Subject.SubjectID == subId).Where(o => o.Semester.SemesterID == semId).FirstOrDefault() != null)
                     {
                         MessageBox.Show("There is already in this semester such subject.","Realisation Update Error");
                         return;
                     }
                     else
                     {
                         var sem = db.Semesters.Find(semId);
                         orig.Semester = sem;
                         var sub = db.Subjects.Find(subId);
                         orig.Subject = sub;
                         orig.TimeStamp = timestamp;
                         db.Realisations.Attach(orig);
                         db.Entry(orig).State = EntityState.Modified;
                         db.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     {
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:40,代码来源:Storage.cs

示例7: updateSemester

 public void updateSemester(int id, string n, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Semesters.Where(orig => orig.SemesterID == id).FirstOrDefault();
             if (original != null)
             {
                 if (!original.Name.Equals(n))
                 {
                     original.Name = n;
                     original.TimeStamp = timestamp;
                     db.Semesters.Attach(original);
                     db.Entry(original).State = EntityState.Modified;
                     db.SaveChanges();
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     {
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:29,代码来源:Storage.cs

示例8: updateSubject

 public void updateSubject(int id, string NewSubName, string NewConspect, string NewUrl, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Subjects.Where(orig => orig.SubjectID == id).FirstOrDefault();
             if (original != null)
             {
                 if (!string.IsNullOrEmpty(NewSubName))
                     original.Name = NewSubName;
                 if (!string.IsNullOrEmpty(NewConspect))
                     original.Conspect = NewConspect;
                 if (!string.IsNullOrEmpty(NewUrl))
                     original.url = NewUrl;
                 original.TimeStamp = timestamp;
                 db.Subjects.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     { throw; }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:29,代码来源:Storage.cs

示例9: updateGroup

 public void updateGroup(int id, string n, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Groups.Where(orig => orig.GroupID == id).FirstOrDefault();
             if (original != null)
             {
                 if (!original.Name.Equals(n))
                 {
                     original.Name = n;
                     original.TimeStamp = timestamp;
                     db.Groups.Attach(original);
                     db.Entry(original).State = EntityState.Modified;
                     db.SaveChanges();
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                     ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:39,代码来源:Storage.cs

示例10: updateStudent

 public void updateStudent(int id, string ind, string first, string last, int groupId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Students.Include("Group").Where(orig => orig.StudentID == id).FirstOrDefault(); 
             if (original != null)
             {
                 if (!string.IsNullOrEmpty(first))
                     original.FirstName = first;
                 if (!string.IsNullOrEmpty(ind))
                     original.IndexNo = ind;
                 if (!string.IsNullOrEmpty(last))
                     original.LastName = last;
                 if (groupId!=original.Group.GroupID )
                 {
                     var group = db.Groups.Find(groupId);
                     original.Group = group;
                 }
                 original.TimeStamp = timestamp;
                 db.Students.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw;
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                 eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                     ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
 }
开发者ID:WezSieTato,项目名称:NtrEres,代码行数:46,代码来源:Storage.cs


注:本文中的DataContext.Entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。