2012-06-26 2 views
1

나는 곤란을 겪고있는 문제가 있습니다.EF 개체에서 버전 변경 찾기

MVC 및 EF와 함께 작업 중이며 사용자가 편집 할 수있는 모델이 있습니다. 편집 된 속성이 다른 사용자가 볼 수 있도록보기에 빨간색으로 표시되어야한다는 새로운 요구 사항이 생겼습니다.

내 모델의 속성은 많지만 기본 키는 GUID이고 모델의 크기는 parentID입니다. 그래서 주어진 GUIDParentID에 대해 어떤 속성이 변경되었는지 확인하고 싶습니다.

지금까지 잘못 느끼는, 나는 단순히 내 아약스 함수에서 true를 반환 그것을하려고하면 다음과 같은

$("[name*='Request.']") 
     .not(":hidden") 
     .each(function() { 
      var $this = $(this); 
      $.ajax({ 
       url: '@Url.Action("IsChanged", "Shared")', 
       data: { fieldName: $this.attr("name"), parentID: @Model.Request.ID }, 
       success: function (data) { 
        if (data) { 
         if ($this.is(":radio")) { 
          $this.parent().addClass("isChanged"); 
         } else 
          $this.addClass("isChanged"); 
        } 
       } 
      }); 
     }); 

이 스크립트는 잘 작동하지 않습니다 내보기에 일부 jQuery를 가지고있다. 그러나 문제는 아약스 함수입니다. 변경 사항을 어떻게 찾습니까? 내가 지금까지 가지고 것은이 : 나는 잘 느끼지 않는다 지금까지했던, 그리고 분명이 작동하지 않습니다,하지만 난 잃었어요 무엇

public ActionResult IsChanged(string fieldName, int parentID) 
    { 
     using (MyEntities _db = new MyEntities()) 
     { 
      string[] aName = fieldName.Split('.'); 

      // Count the number of version 
      int versionCount = _db.SubRequests.Count(r => r.ParentID == parentID); 
      // Get the first version 
      SubRequest sr = _db.SubRequests.FirstOrDefault(r => r.ParentID == parentID); 
      // Check if the count is the same for the specific value 
      int changeCount = _db.ExecuteStoreQuery<int>("select count(parentID) from "+aName[0]+" where parentID = " + parentID + " and " + aName[1] +"='{0}'", THEVALUEINORIGINAL); 


      bool isChanged = changeCount == versionCount; 

      return Json(isChanged, JsonRequestBehavior.AllowGet); 
     } 
    } 

.

이 내용을 이해할 수 있는지 또는 추가 정보가 필요한지 알려주세요. 이 아이디어를 폐기하고 완전히 다른 것을 (아마) 만들어야합니까, 아니면 저를 구할 수있는 방법이 있습니까?

+0

DB 스키마가 어떻게 생겼는지 자세히 설명 할 수 있습니까? 쿼리 할 수있는 데이터가 무엇인지 알기는 어렵습니다. – Ocelot20

답변

0

나는 그것을 할 수있는 가장 좋은 방법은 아니지만, 결국 다른 사람이 비슷한 것을하려고 할 때, 내가 마침내 결정한 솔루션을 공유 할 것이라고 생각했습니다.

내 jQuery를 아약스 기능은 동일하지만 컨트롤러에서 I는 다음과 같습니다 나를 위해

public ActionResult IsChanged(string fieldName, int parentID) 
{ 
    using (MyEntities _db = new MyEntities()) 
    { 
     bool isChanged = false; 

      string[] aName = fieldName.Split('.'); 

      string strTableName = aName[0]; 
      string strFieldName = aName[1]; 

      string strQuery = String.Format("select distinct {0} from {1} where parentID = {2}", strFieldName, strTableName, parentID); 

      isChanged = _db.ExecuteStoreQuery<dynamic>(strQuery).Count() > 1; 

      return Json(isChanged, JsonRequestBehavior.AllowGet); 
    } 
} 

작품 잘. 그러나, 꽤 많은 로딩 페이지와 모든 아약스 호출이 있습니다.

0

동시성 충돌을 올바르게 처리하는 방법을 살펴 보는 것이 좋습니다. this 문서를 확인하십시오.

+0

고마워요,하지만 이건 내가 찾고있는 것이 아닙니다. 동시성 문제가 없습니다. 대신 여러 버전이 있으며 속성이 변경된 경우 쉽게 찾을 수 있습니다. –