2
LINQクエリでC#コードを取得しました。私はRubyに翻訳しようとしていて、SequelをDB ORMとして使用しています。 linqクエリはいくつかの結合を実行し、結合されたエンティティへの参照を含む匿名オブジェクトを返します。私は、コードを変換し、正しく動作しているが、各テーブルからすべての列を返すだけで、C#コードでどのように行われるかと同様に、各列のセットを独自のオブジェクトにラップしたいと思います。Ruby Sequel LINQ to SQLと同等の匿名オブジェクトを選択
LINQクエリ
from s in slots
join tu in _dbContext.table_usages on s.id equals tu.slot_id
join r in _dbContext.Reservations on tu.reservation_id equals r.ReservationID
join o in _dbContext.orders on r.OrderID equals o.OrderID
join c in _dbContext.Contacts on r.ContactID equals c.ContactID
where tu.reservation_id != null &&
r.state != ReservationStates.Cancelled
select new { SlotId = s.id, Reservation = r, Order = o, Contact = c, TableUsage = tu };
Rubyのコード:
select(:slots__id, :reservations.*, :orders.*, :restaurant_customers.*, :table_usages.*)
.filter(slots__restaurant_id: restaurant_id, slots__removed: false)
.filter(slots__slot_time: start_time..end_time)
.join(:table_usages, slot_id: :id)
.join(:reservations, id: :table_usages__reservation_id)
.join(:orders, id: :reservations__order_id)
.join(:restaurant_customers, id: :reservations__contact_id)
.filter('table_usages.reservation_id is not null')
.filter('reservations.state != ?', ReservationStates.cancelled)
私はドキュメントを経由してこれを達成する方法を見つけることができないが、私は誰もがに似た何かを行っている場合、私は見るだろうと思いました私はまだ考えていない方法です。
ありがとうございます!
私はそうではありません、私は最初の行を参照していますが、除外の良い呼び出しです。私はそれらを〜{}でフィルターに変更してそれを逆にしましたが、それははるかに良いです、どうして私はそれを考えなかったのですか? – Jimmy