R – Imported function in Entity Framework Where clause


Is it possible to use a function import in a where clause in entity framework? I have tried the following, but I get a rather cryptic exception to which I cannot find any information about:

var q = MyContext.MyEntities.Where("MyContext.MyFunction(it.ID)")

(The function is set to return a Boolean)

System.Data.EntitySqlException: 'MyContext.MyFunction' cannot be resolved into a valid type constructor or function., near WHERE predicate, line 6, column 21..



Best Solution

The query you are trying to write is composing a call to a FunctionImport with a query over an EntitySet.

But because FunctionImports are wrappers around StoredProcedures, which are non-composable, this just won't work.

In order for something like this to work, theoretically the function would need to be a wrapper around something composable like a TVF (Table Value Function). But unfortunately TVFs aren't supported in the Entity Framework today.