2014-05-15 5 views
2

두 테이블을 조인하려고하면이 오류 메시지가 표시됩니다.linq 조인 오류

형식 인수는 쿼리에서 유추 할 수 없습니다.

오류 (12)는 조인 절에 표현 중 하나의 유형이 잘못되었습니다. 'Join'에 대한 호출에서 형식 유추가 실패했습니다.

var query = (from packagingMainCustom in this.Connection.Tbl_PackagingMaster_Main_Customs 
       join packagingMainSync in this.Connection.Tbl_PackagingMaster_Main_Codes 
        on new { packagingMainCustom.ID_Code, packagingMainCustom.ID_Version } 
        equals new { packagingMainSync.ID_Code, packagingMainSync.ID_CurrentVersion } 
       select packagingMainCustom); 

이 LINQ 쿼리가 작동 :

var query = (from packagingMainCustom in this.Connection.Tbl_PackagingMaster_Main_Customs 
       join packagingMainSync in this.Connection.Tbl_PackagingMaster_Main_Codes 
        on new { packagingMainCustom.ID_Code } 
        equals new { packagingMainSync.ID_Code } 
       select packagingMainCustom); 

따라서 오류 메시지가 packagingMainSync.ID_CurrentVersion 및 packagingMainCustom.ID_Version과 관련이있을 수 있습니다 여기에

는 코드입니다.

//packagingMainCustom 
private long _iD_Version; 
[System.ComponentModel.DataAnnotations.Required()] 
[System.ComponentModel.DataAnnotations.Key()] 
public virtual long ID_Version 
{ 
    get 
    { 
     return this._iD_Version; 
    } 
    set 
    { 
     if(this._iD_Version != value) 
     { 
      this.OnPropertyChanging("ID_Version"); 
      this._iD_Version = value; 
      this.OnPropertyChanged("ID_Version"); 
     } 
    } 
} 

//packagingMainSync 
private long _iD_CurrentVersion; 
[System.ComponentModel.DataAnnotations.Required()] 
public virtual long ID_CurrentVersion 
{ 
    get 
    { 
     return this._iD_CurrentVersion; 
    } 
    set 
    { 
     if(this._iD_CurrentVersion != value) 
     { 
      this.OnPropertyChanging("ID_CurrentVersion"); 
      this._iD_CurrentVersion = value; 
      this.OnPropertyChanged("ID_CurrentVersion"); 
     } 
    } 
} 

둘 사이의 유일한 차이점은 DataAnnotations.Key() Annontations이다 : 여기

두 속성 선언한다.

위의 쿼리가 작동하지 않는 이유는 무엇이며 오류 메시지는 무엇을 의미합니까?

답변

3

더 분명 익명 형식의 회원을 시도 같은 :

on new { Code = packagingMainCustom.ID_Code, 
    Version = packagingMainCustom.ID_Version } 
equals new { Code = packagingMainSync.ID_Code, 
    Version = packagingMainSync.ID_CurrentVersion } 

여기에 주요 변화가 이름이 지금과 일치한다는 것입니다, 순서, 같은 아마도 유형을을처럼; 이것은 실제로 두 장소에서 모두 동일한 익명 유형임을 의미합니다 (익명 유형은 본질적으로 구성원 이름, 순서, 유형 및 선언 어셈블리 조합으로 정의됩니다).

+0

의미가 있습니다. 그리고 당신은 좋은 설명을 해줬습니다. –