Return a result from a database using Entity Framework : <p>I am trying to use this method to return a boolean value based on whether or not the custody already exists in the database.</p>

<pre><code>var custody = db.Custodies.LastOrDefault(c =&gt; c.studentId == id);
if (db.Custodies.Contains(custody) &amp;&amp; custody.custodyEndTime == null)
{
    return true;
}
    return false;
}
</code></pre>

<p>The Custodies table uses a composite primary key but I only want to search by studentId, so I can't use Find(). I want to find the custody entry based on the studentId to check if that student is currently in a custody with no custodyEndTime.</p>

<p>I tried using a linq query but that gave me an anonymous type and it complained about that too.</p>

<p>Any help would be great.</p>

<p>Cheers.</p>
