谁能提供linq查询

时间:2018-06-20 05:47:02

标签: c# linq

现在我想要一个如下的LINQ查询 如果public function filterEventsBy($sportId = null, $eventId = null, $leagueId = null){ $events = $this->model->join('sports_base_rounds', 'sports_base_rounds.s_base_round_id', '=', 'sports_base_events.s_base_round_id') ->join('sports_base_seasons', 'sports_base_rounds.s_base_season_id', '=', 'sports_base_seasons.s_base_season_id') ->join('sports_base_leagues', 'sports_base_seasons.s_base_league_id', '=', 'sports_base_leagues.s_base_league_id') ->join('sports_base_regions', 'sports_base_regions.s_base_region_id', '=', 'sports_base_leagues.s_base_region_id') ->join('sports_base_sports', 'sports_base_sports.s_base_sport_id', '=', 'sports_base_leagues.s_base_sport_id'); if ($sportId) $events->where('sports_base_sports.s_base_sport_id', $sportId); if ($leagueId) $events->where('sports_base_leagues.s_base_league_id', $leagueId); if ($eventId) $events->where('s_base_event_id', $eventId); else $events->where('s_base_event_start_time', '>', Carbon::now()); return $events->get(); } public function getAllSelectionsByMarketId($marketId){ $selections = $this->model->whereIn('s_base_market_id', $marketId) ->get(); if(!$selections) return null; return $selections; } public function getAllMarketsByEventId($eventId){ $markets = $this->model->whereIn('s_base_event_id', $eventId) ->get(); if(!$markets) return null; return $markets; } 是0001或0002,那么我可以使用compIds检查条件 如果divisionCode是0005或0006,则无需与compIds进行核对,因此任何人都可以提出建议divisionCode可能会增加,具体取决于要求

compId

2 个答案:

答案 0 :(得分:0)

我认为只需要添加一些条件...应该是这样的...

string[] compID = new string[] { "0002", "0001", "0005", "0006" };
string[] divisionCode = new string[] { "01021159", "02013350", "02013483", "02013804", "02013375", "02013374", "02013380", "02013398", "02017379", "02013391", "02013444", "02013353", "02004458", "02013394" };
var ACM = (from t1 in Entity.ApprovedContracts
      join t2 in Entity.ApprovedResources
      on t1.ApprovedResourceId equals t2.ResourceGeneralId
      where compID.Contains(t1.OpuCode) && (t1.OpuCode == "0005" || t1.OpuCode == "0006" || divisionCode.Contains(t1.DivisionCode)
      select new
      {
            t1.OpuCode,
            t1.DivisionCode,
            t2.EnterpriseId,
            t2.ResourceEmail
      }).ToList();

答案 1 :(得分:0)

使用这样的LINQ:

var orderDates = t1
                .Join(t2, _t1 => _t1.Id, _t2 => _t2.Id, (p, o) => new { 
                t1.OpuCode,
                t1.DivisionCode,
                t2.EnterpriseId,
                t2.ResourceEmail })
                .Where(r => r.compID.Contains(t1.OpuCode) >= startDate && r.divisionCode.Contains(t1.DivisionCode)).OrderBy(r => r.OrderDate);