c# - Simple.Data One Direction Join on a Table Twice -
i have users table , messages table. messages table has 2 foreign key references users table, "to_id" , "from_id" both pointing user.id. want write query homecoming messages , allow me username property both user represented , relations. here's have far:
dynamic sender; dynamic recipient; var messages= db.messages.all(db.messages.to_id == currentuser.id || db.messages.from_id == currentuser.id) .join(db.users.as("sender"), out sender).on(sender.id == db.messages.from_id) .join(db.users.as("recipient"), out recipient).on(recipient.id == db.messages.to_id) homecoming messages;
the result of query gives me right messages count, to_id , from_id columns disappear , sender , recipient column names not appear. tried looking @ docs, source on github , question here: simple.data - how bi-drectionally bring together on same table twice without success yet. ideas?
i don't know happening to_id , from_id columns, if want eager-load users rows, need add together clauses:
dynamic sender; dynamic recipient; var messages= db.messages.all(db.messages.to_id == currentuser.id || db.messages.from_id == currentuser.id) .join(db.users.as("sender"), out sender).on(sender.id == db.messages.from_id) .join(db.users.as("recipient"), out recipient).on(recipient.id == db.messages.to_id) .with(sender) .with(recipient); homecoming messages;
as missing columns, have tried looking @ trace see sql that's beingness executed query? might help shed light.
c# asp.net-mvc join simple.data
No comments:
Post a Comment