with linq to entities (used with db context), the callback are expression trees, not code. the expression tree is a small ast tree of the lambda code. when the query is executed, the driver converts the expression tree to sql syntax. the driver are very restrictive (unlike the compiler) in what code is allowed in the expression.
https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/expression-trees/
in you case the driver is telling you it can can not convert the function "p" to sql. how would the SQL Server execute the c# function? how would the driver get the code of the function to generate sql?
note: some drivers allow you to create sql function and install in the database, and map to a function name.