{"action":"created","issue":{"url":"https://api.github.com/repos/OData/WebApi/issues/487","labels_url":"https://api.github.com/repos/OData/WebApi/issues/487/labels{/name}","comments_url":"https://api.github.com/repos/OData/WebApi/issues/487/comments","events_url":"https://api.github.com/repos/OData/WebApi/issues/487/events","html_url":"https://github.com/OData/WebApi/issues/487","id":101895961,"number":487,"title":"Filtering by OpenTypes doesn't work with Linq to Entity","user":{"login":"katan4ig","id":11876236,"avatar_url":"https://avatars.githubusercontent.com/u/11876236?v=3","gravatar_id":"","url":"https://api.github.com/users/katan4ig","html_url":"https://github.com/katan4ig","followers_url":"https://api.github.com/users/katan4ig/followers","following_url":"https://api.github.com/users/katan4ig/following{/other_user}","gists_url":"https://api.github.com/users/katan4ig/gists{/gist_id}","starred_url":"https://api.github.com/users/katan4ig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katan4ig/subscriptions","organizations_url":"https://api.github.com/users/katan4ig/orgs","repos_url":"https://api.github.com/users/katan4ig/repos","events_url":"https://api.github.com/users/katan4ig/events{/privacy}","received_events_url":"https://api.github.com/users/katan4ig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-19T13:37:56Z","updated_at":"2015-08-20T11:46:20Z","closed_at":null,"body":"I store the data for the open types in the database, and I implemented dynamic initialization for them.\r\nI'm using the latest version of OData v4 and EF 6. \r\n\r\nMy model: \r\n```\r\npublic class ExampleDto\r\n{\r\n        private IEnumerable<CustomAttribute> _customAttributes { get; set; }\r\n        public IEnumerable<CustomAttribute> Attributes\r\n        {\r\n            get { return _customAttributes ?? (_customAttributes = new List<CustomAttribute>()); }\r\n            set { _customAttributes = value; }\r\n        }\r\n\r\n        private IDictionary<string, object> _dynamicAttributes { get; set; }\r\n        public IDictionary<string, object> DynamicAttributes\r\n        {\r\n            get\r\n            {\r\n                _dynamicAttributes = new Dictionary<string, object>();\r\n                if (Attributes != null && Attributes.Any())\r\n                {\r\n                    _dynamicAttributes = Attributes.ToDictionary(s => s.Name, s => s.Value);\r\n                }\r\n                return _dynamicAttributes;\r\n            }\r\n            set { _dynamicAttributes = value; }\r\n        }\r\n}\r\n```\r\n\"Attributes\" field initialization:\r\n```\r\nvar attributes = _exampleRepository.Select(s => new ExampleDto() \r\n{ \r\n   Attributes = new CustomAttribute()\r\n   {\r\n     Name = s.Name,\r\n     Value = s.Value \r\n   }\r\n}\r\n\r\nreturn Ok(attributes)\r\n```\r\nThis works fine, but if I try to use OData filters, Web API to throw next exception: \r\n\"Unknown LINQ expression of type 'Index'\"\r\n\r\nThis exception thrown only with filtering by open types.\r\nAlso, this method work if I use ToList() function before applies Odata filters.\r\nBut i can't use this way because, if used ToLIst() before filtering then i get all data from DB. \r\nThis is not a good solution for performance.\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/OData/WebApi/issues/comments/132983841","html_url":"https://github.com/OData/WebApi/issues/487#issuecomment-132983841","issue_url":"https://api.github.com/repos/OData/WebApi/issues/487","id":132983841,"user":{"login":"katan4ig","id":11876236,"avatar_url":"https://avatars.githubusercontent.com/u/11876236?v=3","gravatar_id":"","url":"https://api.github.com/users/katan4ig","html_url":"https://github.com/katan4ig","followers_url":"https://api.github.com/users/katan4ig/followers","following_url":"https://api.github.com/users/katan4ig/following{/other_user}","gists_url":"https://api.github.com/users/katan4ig/gists{/gist_id}","starred_url":"https://api.github.com/users/katan4ig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katan4ig/subscriptions","organizations_url":"https://api.github.com/users/katan4ig/orgs","repos_url":"https://api.github.com/users/katan4ig/repos","events_url":"https://api.github.com/users/katan4ig/events{/privacy}","received_events_url":"https://api.github.com/users/katan4ig/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T11:46:20Z","updated_at":"2015-08-20T11:46:20Z","body":"Model defined into Linq To Entity expression, how it described above. \r\n```\r\n_exampleRepository.Select(s => new ExampleDto()  <= determination new DTO model for each DB item \r\n{ \r\n   Attributes = new CustomAttribute()  <= determination Name Value collection for the Open Type\r\n   {\r\n     Name = s.Name,\r\n     Value = s.Value \r\n   }\r\n}\r\n```\r\nProperty \"Attributes\" initialized into query.\r\nProperty \"DynamicAttributes\" from ExampleDto initialized based on \"Attributes\" property, when API causes him getter.\r\n\r\nResult without $filter condition, for example:\r\n```\r\n[{\r\n    Attributes:[\r\n         {\r\n                Name : \"DynamicField1\",\r\n                Value : \"1\"\r\n         },\r\n         {\r\n                Name : \"DynamicField2\",\r\n                Value : \"2\"\r\n          },\r\n          {\r\n                Name : \"DynamicField3\",\r\n                Value : \"3\"\r\n          },\r\n          {\r\n               Name : \"DynamicField4\",\r\n               Value : \"4\"\r\n          }\r\n     ],\r\n     DynamicField1:\"1\",\r\n     DynamicField2:\"2\",\r\n     DynamicField3:\"3\",\r\n     DynamicField4:\"4\"\r\n},\r\n{\r\n    Attributes:[\r\n         {\r\n                Name : \"DynamicField1\",\r\n                Value : \"5\"\r\n         },\r\n         {\r\n                Name : \"DynamicField2\",\r\n                Value : \"6\"\r\n          },\r\n          {\r\n                Name : \"DynamicField3\",\r\n                Value : \"7\"\r\n          },\r\n          {\r\n               Name : \"DynamicField4\",\r\n               Value : \"8\"\r\n          }\r\n     ],\r\n     DynamicField1:\"5\",\r\n     DynamicField2:\"6\",\r\n     DynamicField3:\"7\",\r\n     DynamicField4:\"8\"\r\n}]\r\n```\r\nApi returned objects with all dynamic properties(Open Types).\r\n\r\nFilter condition which thrown exception:\r\n```\r\n$filter=DynamicField1 eq '1'\r\n```\r\nLet me know if you need more information.\r\nThanks.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}