Although it might not help but it pains me to read this:

"select * from jobs where databaseserverid in ( select databaseserverid from databaseservers where isactive = 1 )"

what happened to good old joins?

"select * from Jobs j left join databaseservers dbs on j.DatabaseServerID = dbs.DatabaseServerID where dbs.isactive = 1"

anyway, in ActiveRecord you should be able do it like this:

|ActiveRecordBase<Jobs>.||FindAll(||Expression.Eq(||"||DatabaseServer.IsActive"||, true));| // which I think will result in the join query.

Cheers
Christian

On 9/08/2013 09:28, Michael wrote:
Hi all. I'm a little stumped on the best way to accomplish this query. I have an object, Jobs, which maps to a database table with the following columns:

ID
Name
Description
DatabaseServer

DatabaseServer is also an object which maps to the DatabaseServers table with the following columns:

ID [Column = "DatabaseServerID")]
Description
IsActive (bool)

Normally, if I wanted to query the Jobs table, I would use something like the following: ActiveRecordBase<Jobs>.FindAll().ToList();

The problem I have is I want to use this same method to query based off whether the a job has a DatabaseServer that IsActive.

I've tried the following:
ActiveRecordBase<Jobs>.FindAll().Where(x => x.DatabaseServer.IsActive).ToList();

But, this takes forever to run. I have approximately 5000 records in the jobs, table.

Using straight sql, this is really quick and easy: select * from jobs where databaseserverid in ( select databaseserverid from databaseservers where isactive = 1 )

But, I'm trying to return a List<Job> object, and don't want to get a DataSet and manually map it to my Job object for each row in the Dataset.

Any ideas on how to efficiently accomplish this? Sorry if I've overlooked something completely obvious. I'm getting tunnel vision at this point.
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "Castle 
Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to