, linq-to-objects, linq-to-sql. Func<X, bool>, linq-to-objects, linq-to-sql ( IQueryable) , - )
- Compile() , .
a.Comments.Count(CommentSpecifications.IsUnread(actorId, a.LastView).Compile())
, , linq-to-objects, linq-to-sql. , , sql, .
Update
, :
linq-to-objects linq-to-sql. Func<> Compile() , linq-to-sql .
2
, , - . Linq-to-sql , linq-to-entity, . , IQueryable<T>.
public static IQueryable<Comment> WhereIsUnread(this IQueryable<Comment> src, int userId)
{
return src.Where(
c =>
!c.Deleted && c.CreatedByActorID != actorId
&& (viewed == null || c.ItemCreatedDate > c.Alert.LastView.LastViewedDate));
}
...
return (from a in alerts
select
new UnreadComments
{
TotalNumberOfUnreadComments =
a.Comments.WhereIsUnRead(actorId).Count()
})
- . , , SQL .