I am creating a int value has follows:
int result = db.Posts.Where(p => p.IsPublished == true &&
CheckPostDate(s.CreatedAt).GetValueOrDefault(false) == true).Count();
I get the error:
Method 'System.Nullable`1[System.Boolean]
CheckPostDate(System.Nullable`1[System.DateTime])' has no supported
translation to SQL.
Can't I call a function I created in a Linq query?
How can I solve this problem?
Thanks,
Miguel
Fair cop - but it would have worked with LINQ-to-Objects...
Sorry for any confusion...
You mean:
int result = db.Posts.Where(p => p.IsPublished == true (&&
CheckPostDate(s.CreatedAt) ?? false)).Count();
I still get the same error. I don't think that's the problem.
Here's a trivial example:
[Function(Name="NEWID", IsComposable=true)]
public Guid Random()
{ // to prove not used by our C# code...
throw new NotImplementedException();
}
At the DB this will become TSQL calling NEWID() - but you can have
parameters etc as you need.
Noet that this only works with some LINQ providers (I belive LINQ-to-SQL
supports it, EF doesn't), and the method needs to be on the data-context.
Marc