나는 사람들이 다른 사람들을보기 위해 querystring
을 변경 중지하는 데 사용하려고 다음과 같은 방법을 자세히 설명했다 :재정이 IEquatable
public static bool IsCurrentUserAuthorisedVessel(HttpRequest request)
{
Guid currentUser = GetCurrentUserId();
PersonRepository repo = new PersonRepository();
VesselRepository vesselRepo = new VesselRepository();
Person currentPerson = repo.GetPersonByUser(currentUser);
int qs = int.Parse(request.QueryString["VesselId"]);
Vessel currentVessel = vesselRepo.GetVessel(qs);
if (!String.IsNullOrEmpty(request.QueryString["VesselId"]))
{
if (IsCurrentUserAdmin())
{
return true; //Always return true for admin
}
else
{
if (currentPerson.Vessels.Contains(currentVessel))
{
return true;
}
else
return false;
}
}
return true;
}
을 나는 현재 currentPerson.Vessels
수익률 3 개 혈관을 디버깅하고 예에서 Icollection<Vessel>
중 하나는 VesselId
인 6을 가지며이 역시 역시 currentVessel
의 VesselId가됩니다. 그러나 일치가 실패하고 메서드가 false
을 반환합니다.
ICollection 내에서 ID가 6 인 선박이 currentVessel의 다른 인스턴스이기 때문에 비슷한 질문과 MSDN 설명서에 대한 일부 내용을 읽었습니다. 여기서 무슨 일이 일어나고 있는지 이해하고 있습니다. 참조가 동일하지 않게되고 평등 규칙과 관련이있는 것은 ID를 기반으로하지 않습니다.
는내 Person
모델이 내 Vessel
모델에 IEquatable
인터페이스를 구현하고 Equals 메서드를 오버라이드 (override) 할 필요가 있음을 의미 하는가 public virtual ICollection<Vessel> Vessels { get; set; }
가 포함되어 있습니다.
나는이 인스턴스에서 동일성에 대한 ID를 기반으로 사용자 정의 규칙을 원합니다. 이 방법을 어떻게 재정의합니까? 이 상황에서 Equals
재정
사용중인 ORM (Entity Framework, NHibernate 등)의 태그를 추가하십시오. –