Hi Michael,
Here is one way but there are others too. Note that there are multiple
overloads for FindAll(). You could use the one which take a
DetachedCriteria. A lot of people (well, at least me) will create a
separate static class to hold complex 'queries.' Example:
Your code where you need to get the jobs:
var jobs = Job.FindAll(Queries.GetJobsByDatabaseServerStatus(true));
Your 'queries' class:
public static class Queries
{
public static DetachedCriteria GetJobsByDatabaseServerStatus(bool
isActiveDatabaseServer)
{
return DetachedCriteria.For<Jobs>()
.Add(Expression.Eq("DatabaseServer.IsActive",
isActiveDatabaseServer));
}
}
HTH.
Cheers,
Eric
On Thu, Aug 8, 2013 at 2:28 PM, Michael <[email protected]> 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.
>
>
>
--
*Eric Tarasoff*
linkedin.com/in/tarasoff
twitter.com/etarasoff
--
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.