{"action":"created","issue":{"url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/18","labels_url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/18/comments","events_url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/18/events","html_url":"https://github.com/jcachat/EntityFramework.DynamicFilters/issues/18","id":57671450,"number":18,"title":"Can I dynamically provide the primary key column as the filtered property?","user":{"login":"wbraun","id":1276402,"avatar_url":"https://avatars.githubusercontent.com/u/1276402?v=3","gravatar_id":"","url":"https://api.github.com/users/wbraun","html_url":"https://github.com/wbraun","followers_url":"https://api.github.com/users/wbraun/followers","following_url":"https://api.github.com/users/wbraun/following{/other_user}","gists_url":"https://api.github.com/users/wbraun/gists{/gist_id}","starred_url":"https://api.github.com/users/wbraun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wbraun/subscriptions","organizations_url":"https://api.github.com/users/wbraun/orgs","repos_url":"https://api.github.com/users/wbraun/repos","events_url":"https://api.github.com/users/wbraun/events{/privacy}","received_events_url":"https://api.github.com/users/wbraun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-14T00:16:07Z","updated_at":"2015-02-14T16:39:46Z","closed_at":null,"body":"Really cool project!  \r\n\r\nI'm working on an authorization app and I would love to use these filters to do row level security. In your examples, you show how you can use a delegate/func to provide a list of values to filter against.  Do you think this approach can also provide the primary key column as the filtered property?  Assume each entity has only one primary key of type int.\r\n\r\nIt would be cool to not need to create filters for every entity whose rows I want to secure.  I was thinking this may be possible by implementing a function that returns the primary key value for the entity, but I'm not sure. The filter below my help you understand what I'm trying to achieve.\r\n\r\nmodelBuilder.Filter(\"FilterByPK\", (IFilterByPrimaryKey m, List<int> valueList) => valueList.Contains( GetAuthorizedPrimaryKeyValues(m) ),true);\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/comments/74381874","html_url":"https://github.com/jcachat/EntityFramework.DynamicFilters/issues/18#issuecomment-74381874","issue_url":"https://api.github.com/repos/jcachat/EntityFramework.DynamicFilters/issues/18","id":74381874,"user":{"login":"jcachat","id":1613260,"avatar_url":"https://avatars.githubusercontent.com/u/1613260?v=3","gravatar_id":"","url":"https://api.github.com/users/jcachat","html_url":"https://github.com/jcachat","followers_url":"https://api.github.com/users/jcachat/followers","following_url":"https://api.github.com/users/jcachat/following{/other_user}","gists_url":"https://api.github.com/users/jcachat/gists{/gist_id}","starred_url":"https://api.github.com/users/jcachat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcachat/subscriptions","organizations_url":"https://api.github.com/users/jcachat/orgs","repos_url":"https://api.github.com/users/jcachat/repos","events_url":"https://api.github.com/users/jcachat/events{/privacy}","received_events_url":"https://api.github.com/users/jcachat/received_events","type":"User","site_admin":false},"created_at":"2015-02-14T16:39:46Z","updated_at":"2015-02-14T16:39:46Z","body":"Sorry, but I don't think there is a way to do what you're asking.\r\n\r\nThe filter expression (where you have your Contains()) is compiled by EF the first time it's executed.  When that happens, all we're really doing is converting that lambda expression into an EF DbExpression that contains parameter references (in this case to \"valueList\").  It does not actually get executed or return any values.  And that conversion will not know how to handle external functions like your GetAuthorizedPrimaryKeyValues() method as there is no way to convert that into an EF DbExpression.\r\n\r\nWhen the SQL statement is executed, we intercept it and provide values for the parameters that were created into the DbExpression when it was compiled.  Those values are provided by the last parameters of the Filter() method - in your example, that's \"true\" (which is obviously not valid for a List).  And during the interception, there isn't even a specific Table Name I could provide since all I have is a SQL statement and the table being filtered could be one of many tables referenced in that statement.\r\n\r\nI know it's not as clean and you're trying to avoid this, but I think your only option is to create a filter on every entity like this:\r\n```\r\nmodelBuilder.Filter(\"FilterByPK\", (Entity1 m, List valueList) => valueList.Contains(m.ID), () => GetAuthorizedPrimaryKeyValuesForEntity1());\r\n```\r\n"}}