Closed erik-kle closed 9 years ago
Hey @erik-kle, I'd be happy to try to help you out!
What exactly are you trying to do? There is some documentation here that shows quite a bit of how to use the driver:
Thanks in advance @karlgrz :)
Im just trying to join TableA with TableB using EqJoin. Im really new to rethinkdb, but more used to sql. So im trying to achive a simple inner join but dont really understand what the syntax should look like.
Db.Table
I know that the syntax looks like this in rethink, and it works. But i dont know how to translate this into c# r.db('db').table("tablea").eqJoin("Id", r.db('db').table('tableb'))
You start by defining the object schemas that you'd like to see from the C# side:
[DataContract]
class User
{
[DataMember]
int userId;
[DataMember]
string name;
}
[DataContract]
class Office
{
[DataMember]
int officeId;
[DataMember]
int userId;
}
Then you tell rethinkdb-net about your two RethinkDB tables, and that they map to those two objects:
var myDb = Query.Db("my-database-name");
var userTable = myDb.Table<User>("user");
var officeTable = myDb.Table<Office>("office");
And then performing an EqJoin is done like this:
var query = userTable.EqJoin(user => user.userId, officeTable);
foreach (var record in connection.Run(query)) {
...
}
The expression user => user.userId
is telling the EqJoin what field to join on, and then the officeTable reference is what table to join to userTable. The variable record
will be of type Tuple<User, Office>
. You can access the user with record.Item1
, and the joined office with record.Item2
.
Thank you @mfenniak. It works :)
I have problem with getting an EqJoin to work in C#. Is there someone who can show me the correct syntax that I should use?