맞춤형 직원 모듈을 만들고 있습니다. 직원은 최대 3 개의 주소를 가질 수 있습니다. 이 기사를 따르려고합니다. http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations한 명의 직원에게 여러 개의 주소 첨부하기
이것은 Migrations.cs에서 가지고있는 것입니다.
SchemaBuilder.CreateTable("EmployeeRecord",
table => table
.ContentPartRecord()
.Column<int>("EmployeeId")
...
.Column<int>("AddressRecord_Id")
);
SchemaBuilder.CreateTable("AddressRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
...
);
다음은 모델입니다.
public class EmployeeRecord : ContentPartRecord {
public virtual int EmployeeId { get; set; }
...
public virtual AddressRecord AddressRecord { get; set; }
}
public class AddressRecord {
public virtual int Id { get; set; }
...
}
create-new-employee 양식을 제출하면 여러 개의 주소가있는 데이터가 표시됩니다. 새 직원 콘텐츠 유형을 만들 수 있습니다. 그러나 그 직원에게 3 개의 주소를 만들고 할당하는 방법을 모르겠습니다. 도움이 되었습니까?
감사합니다.
기본 데이터베이스 디자인에 대해 생각하지 않았습니다. 내가 할 수있는 한이 기사를 자세히 읽으려고했다. Orchard에서 1-n 관계를 구현하는 데 대한 다른 예가 있습니까? 위 링크의 주소/상태 예제는별로 도움이되지 않았습니다. – user471317
글쎄, 기사를 자세히 읽지는 않았는데, 관계가 거꾸로되어있는 것을 보았습니다. 그 기사가 도움이되지 않는다는 것을 어떻게 설명 할 수 있습니까? –
이 기사는 쉽지 않다. 주소/국가는 1-n 관계에 대한 좋은 예가 아니다. 이것은 기사에서 볼 수있는 것으로 AddressPartRecord에는 StateRecord가 있고 AddressPartRecord 테이블에는 StateRecord_Id가 있습니다. 'code' 공용 클래스 AddressPartRecord : ContentPartRecord { ... 공용 가상 StateRecord StateRecord {get; 세트; }} ... SchemaBuilder.CreateTable ("AddressPartRecord" 테이블 => ... 테이블 .Column ("StateRecord_Id") ...); 'code' –
user471317