Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing func as parameter in Linq to Entities and 'Internal .NET Framework Data Provider error 1025' error
    text
    copied!<p>We have a class called Task:</p> <pre><code>public partial class Task : EntityObject { public EntityCollection&lt;TaskUser&gt; TaskUsers { get {...} set{...} } } </code></pre> <p>It has navigation property called TaskUsers, which contains users attached to this taks:</p> <pre><code>public partial class TaskUser : EntityObject { public User User { get {...} set { } } } </code></pre> <p>Every TaskUser object has User object.</p> <p>We are given <code>IQueryable&lt;Task&gt; tasks</code>. We want to find tasks assigned to user with ID = 1. When we use</p> <pre><code>tasks.Where(t =&gt; t.TaskUsers.Any(a =&gt; a.User.ID == 1)) </code></pre> <p>everything works fine. When we use</p> <pre><code>Func&lt;TaskUser, bool&gt; function = a =&gt; a.User.ID == 1; return tasks.Where(t =&gt; t.TaskUsers.Any(function)); </code></pre> <p>we get nice <code>'Internal .NET Framework Data Provider error 1025'</code> error. Why? I want to build much more complicated filters using <code>Expression</code> class, but if I can't pass simple <code>Func</code>, this can't be done. What should I do?</p> <p><strong>EDIT</strong></p> <p>Maybe </p> <pre><code>Func&lt;TaskUser, bool&gt; function = a =&gt; a.User.ID == 1; return tasks.Where(t =&gt; t.TaskUsers.Any(function)); </code></pre> <p>doesn't work, but </p> <pre><code>Expression&lt;Func&lt;TaskUser, bool&gt;&gt; expression = a =&gt; a.User.ID == 1; return tasks.Where(t =&gt; t.TaskUsers.AsQueryable().Any(expression)); </code></pre> <p>works! That is all I needed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload