Joins, OrderBy, etc on Find and FindBy statements?

79 views
Skip to first unread message

Kyle Fisher

unread,
Apr 26, 2012, 12:25:51 PM4/26/12
to Simple.Data
Is there a way to do a Join or an OrderBy when using a Find or
FindBy? I want to return a single record, but it seems that after the
Find(expr), the rest of the statement does not get evaluated?

// Sample join
var result =
db.Table.Find(db.Table.Field1 == "A")
.Join(db.Table2)
.On(db.Table.Field2 == db.Table2.Field2 &&
db.Table2.Field3 == "N");

Ideally trying to reproduce something like this:

SELECT TOP 1 [fields] FROM Table
JOIN Table ON Table.Field2 == Table2.Field2 AND Table2.Field3 = 'N'
WHERE Table.Field1 = 'A'

// Sample Order By
var result = db.Table.FindByField1("A").OrderByField2();

Trying to do something like this:
SELECT TOP 1 [fields] FROM Table WHERE Field1 = 'A' ORDER BY Field2

Thanks for the help!

Kyle

Mark Rendle

unread,
Apr 26, 2012, 2:21:18 PM4/26/12
to simpl...@googlegroups.com

Do a FindAll or FindAllBy and call .Take(1).SingleOrDefault() on the end and it will do the TOP 1 bit in the SQL.

M

nkaiseng safnate

unread,
Apr 28, 2012, 7:10:44 PM4/28/12
to simpl...@googlegroups.com
Please remove me from Simpl...@googlegroups.com
 
"Don't be afraid to be wrong; otherwise you'll never be right."

From: Mark Rendle <ma...@markrendle.net>
To: simpl...@googlegroups.com
Sent: Thursday, April 26, 2012 8:21 PM
Subject: Re: Joins, OrderBy, etc on Find and FindBy statements?

Mark Rendle

unread,
Apr 29, 2012, 6:21:28 AM4/29/12
to simpl...@googlegroups.com
You can unsubscribe from the Google Groups page.

Sent from my iPad (until Win8 gets a mail app)
Reply all
Reply to author
Forward
0 new messages