2012-01-25 3 views
0

개체 모델을 응용 프로그램으로 설계하고 있으며 개체와 테이블간에 임피던스 불일치가 확실합니다. 예를 들어 내가 가진 : ORM을 사용한 도메인 기반 디자인

Product 
----------- 
ProductId, 
ProductTypeCode, 
StatusCode, 
SKUNumber 


ProductMarketAvailability 
-------------------------- 
ProductMarketAvailabilityId, 
ProductId, 
MarketId, 
Rank 

ProductDescription 
------------------ 
ProductDescriptionId, 
ProductId, 
MarketId, 
StatusId, 
DescriptionTypeId, 
Description 

이 (내가 룩업 테이블을 설명 didnt가 : 상태, DescriptionType, ProductType, 시장)


나는 도메인 클래스 갖고 싶어 :

Product 
-------------- 
ProductId, 
SkuNumber, 
MarketId, 
MarketName, 
StatusCode, 
Status, 
Title , 
Description, 
Caption, 
Rank 

LLblGen 프로 또는 Entity Framework 포함 :

- how i can map these tables my domain class? 
- Is it a best way to deal with this through Domain classes or better to 
    isolate domain classes from ORM generated classes 
    - If I manually map ORM classes data to my domain classes then when i 
    persisting my Domain classes (imagine they are POCO Self tracking), 
    how can i write managable , well crafted code ? 

i dont want to write , it doesnt look so right to me: 

    if (myProduct.TitleisDirty) 
    { 
     ProductDescription p= myRepository.GetDescriptionById 
     (myProduct.ProductDescriptionIdForTitle); 
     p.Description=myProduct.Title; 
     p.SubmitChanges(); 
    } 
    if (myProduct.RankisDirty) 
    { 
     ProductMarketAvailability pma= myRepository.GetMarketById 
     (myProduct.ProductMarketAvailabilityId); 
     pma.Rank=myProduct.Rank; 
     pma.SubmitChanges(); 
    } 

읽어 주셔서 감사합니다.

답변

0

이 테이블을 하나의 클래스 (적어도 EF에서는 아님)에 매핑 할 수 있다고 생각하지 않습니다. 모델은 제품과 다른 테이블 간의 일대일 관계를 전달합니다. 그들이 동일한 기본 키 (진정한 1 : 1)를 공유한다면 그것을 하나의 엔티티로 매핑 할 수 있습니다. 다른 질문에 대해서는

: 그것은 최고의 도메인 클래스를 통해이 처리하는 방법 또는 ORM 클래스를 생성에서 분리 도메인 클래스에 더 나은

  • 인가?

    수동 ontop의 당신의 ORM-클래스의 또 다른 모델을 만들기 위해 시작하지 않는 (당신이 할 경우 코드를 우선 그들은 어쨌든 포항 강판이어야 함), 선택의 ORM 툴에서 클래스를 사용하여
  • 수동으로 ORM 클래스 데이터를 내 도메인 클래스에 매핑하면 도메인 클래스 (POCO 자체 추적이라고 가정)를 유지할 때 관리자가 잘 작성된 코드를 어떻게 작성할 수 있습니까?

할 수 있습니다하지

나는이 레거시 응용 프로그램은 추측하고 당신은 나의 제안이 여러 클래스로 테이블을 매핑 한 다음 요청하는 기능을 노출하는 데이터베이스를 만지지 수 Product 클래스를 통해 래퍼로. 예 : Product.MarketAvailability.Rank는 Product : Product.Rank의 래퍼 속성이됩니다.

관련 문제