EntityFramework를 사용하여 데이터베이스에 프로젝트 버전 번호를 저장합니다. . UI 페이지에서 사용자가 버전 (major, minor, build) 정수 값을 입력하고 저장 버튼을 클릭하십시오. 전에 저장, DB에 중복 버전이 생성되지 않도록하고 싶습니다.엔터티 프레임 워크 중복되는 항목을 방지하는 방법
는 내가 무엇을 시도하고 추가하려는 것과 같은 세부 사항을 데이터베이스에 항목이있는 경우에 major.minor.build 조합이
ProjVersion newVersion=new ProjVersion();
newVersion.Major=10;
newVersion.Minor=1;
newVersion.Build=1;
this.repository.Add<ProjVersion>(newVersion);
//here how can I ensure that no duplicate versions are added to database
this.repository.SaveChanges();
[Serializable]
public class ProjVersion
{
[Key]
public int Version_Id { get; set; }
public int Major { get; set; }
public int Minor { get; set; }
public int Build { get; set; }
}
그리고 "using (TransactionScope tsTransScope = new TransactionScope())"를 추가하십시오. – Ubikuity
version_id는 자동으로 생성 된 number.so이므로 새 레코드가 추가 될 때마다 version_id로 새 번호가 생성됩니다. 그러나 여기에서 major.minor.build 조합이 고유한지 확인하는 것이 좋습니다 – Millar
@Millar, 예 그건 내 실수 였어. 지금 정확한 코드를 보여주기 위해 편집되었습니다. –