2
我嘗試連接兩個表,並以此錯誤消息結束。linq加入時出錯
無法從查詢中推斷出類型參數。
和
錯誤12聯接子句中的類型的表達式中的一個的不正確。在「加入」的調用中,類型推斷失敗。
這裏是代碼:
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。
爲什麼上面的查詢不起作用,錯誤信息是什麼意思?
它是有道理的。你提供了一個很好的解釋 –