2012-06-17 3 views
-3

내 프로젝트에서 Entity Framework 5를 사용하고 있는데 레코드를 업데이트하려고합니다. 어떻게해야합니까?Entity Framework의 업데이트

내 기본 클래스는 다음과 같습니다.

using System; 

namespace EF_Sample09.DomainClasses 
{ 
    public abstract class BaseEntity 
    { 
     public int Id { get; set; } 

     public DateTime CreatedOn { set; get; } 
     public string CreatedBy { set; get; } 

     public DateTime ModifiedOn { set; get; } 
     public string ModifiedBy { set; get; } 
    } 
} 
+1

EF를 사용하여 업데이트를 수행하는 방법의 예가 필요하다고 가정합니다. –

+0

no.iwant 데이터 업데이트 – Mohammad

답변

0

ADO.NET Entity Framework Overview에서 촬영 :

using(AdventureWorksDB aw = new 
AdventureWorksDB(Settings.Default.AdventureWorks)) { 
    // find all people hired at least 5 years ago 
    Query<SalesPerson> oldSalesPeople = aw.GetQuery<SalesPerson>(
     "SELECT VALUE sp " + 
     "FROM AdventureWorks.AdventureWorksDB.SalesPeople AS sp " + 
     "WHERE sp.HireDate < @date", 
     new QueryParameter("@date", DateTime.Today.AddYears(-5))); 

    foreach(SalesPerson p in oldSalesPeople) { 
     // call the HR system through a webservice to see if this 
     // sales person has a promotion coming (note that this 
     // entity type is XML-serializable) 
     if(HRWebService.ReadyForPromotion(p)) { 
      p.Bonus += 10; // give a raise of 10% in the bonus 
      p.Title = "Senior Sales Representative"; // give a promotion 
     } 
    } 

    // push changes back to the database 
    aw.SaveChanges(); 
} 

에 당신은 기본적으로 그냥 가지고 :

  • ObjectContext (또는 DbContext)
  • 가져 오기 일부 레코드를 만들
  • 을 수정 객체
  • 전화 그것의 데이터베이스

로 다시 변경 사항을 작성하는 문맥의 .SaveChanges() 방법!