我有LINQ查詢,如下字符串轉換爲在LINQ的GUID連接查詢:條件語句
using (RMPortalEntities _RMPortalEntities = new RMPortalEntities()) {
var _RSVP_ButtonLocations = _RMPortalEntities
.tbl_RSVP_ButtonLocation
.Join(_RMPortalEntities.tbl_RSVP_Setting,
_RSVP_ButtonLocation => Guid.Parse(_RSVP_ButtonLocation.ID),
_RSVP_Setting => _RSVP_Setting.RSVP_Button_Location_ID,
(_RSVP_ButtonLocation, _RSVP_Setting) => new { _RSVP_ButtonLocation, _RSVP_Setting })
.Join(_RMPortalEntities.tbl_Event,
_RSVP_ButtonLocation_RSVP_Setting => _RSVP_ButtonLocation_RSVP_Setting._RSVP_Setting.EventID,
_Event => _Event.ID,
(_RSVP_ButtonLocation_RSVP_Setting, _Event) => new { _RSVP_ButtonLocation_RSVP_Setting, _Event })
.Where(x => x._Event.Active == true
&& x._Event.ID == _EventID)
.Select(x => new
{
RSVP_ButtonLocations = x._RSVP_ButtonLocation_RSVP_Setting._RSVP_ButtonLocation.RSVP_ButtonLocation
});
return _RSVP_ButtonLocations.FirstOrDefault().RSVP_ButtonLocations;
}
但問題是,LINQ查詢不允許我字符串轉換爲GUID值。 任何人都可以給我建議嗎?
怎麼樣,而不是「Guid.Parse(_RSVP_ButtonLocation「新的GUID(_RSVP_ButtonLocation.ID)」。 ID)」 ? – CjCoax
@CjCoax,我按照你的建議更新,我得到這個消息「System.NotSupportedException:LINQ to Entities只支持無參數的構造函數和初始值設定項。」 「 –
@Frank,爲什麼用於連接的數據類型有所不同?也許最好是在兩個表中都有'Guid'?如果不是,可能你可以嘗試進行連接:將Guid轉換爲字符串,所以連接字符串值... – horgh