0

我有如下的 linq 查询

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 值。有人可以给我建议吗?

4

1 回答 1

0

Building on CjCoax comment you can store an instance of GUID and then use it later in the query:

using (RMPortalEntities _RMPortalEntities = new RMPortalEntities()) {
            var GUID = new Guid(_RMPortalEntities.tbl_RSVP_ButtonLocation.ID);
            var _RSVP_ButtonLocations = _RMPortalEntities
                                        .tbl_RSVP_ButtonLocation
                                        .Join(_RMPortalEntities.tbl_RSVP_Setting,
                                                        _RSVP_ButtonLocation => GUID,
                                                        _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;
        }
于 2012-11-19T04:05:45.027 回答