{"action":"created","issue":{"url":"https://api.github.com/repos/ServiceStack/Issues/issues/455","repository_url":"https://api.github.com/repos/ServiceStack/Issues","labels_url":"https://api.github.com/repos/ServiceStack/Issues/issues/455/labels{/name}","comments_url":"https://api.github.com/repos/ServiceStack/Issues/issues/455/comments","events_url":"https://api.github.com/repos/ServiceStack/Issues/issues/455/events","html_url":"https://github.com/ServiceStack/Issues/issues/455","id":163672106,"number":455,"title":"OrmLite:  third bug in Sql.In","user":{"login":"OlegNadymov","id":9961359,"avatar_url":"https://avatars.githubusercontent.com/u/9961359?v=3","gravatar_id":"","url":"https://api.github.com/users/OlegNadymov","html_url":"https://github.com/OlegNadymov","followers_url":"https://api.github.com/users/OlegNadymov/followers","following_url":"https://api.github.com/users/OlegNadymov/following{/other_user}","gists_url":"https://api.github.com/users/OlegNadymov/gists{/gist_id}","starred_url":"https://api.github.com/users/OlegNadymov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OlegNadymov/subscriptions","organizations_url":"https://api.github.com/users/OlegNadymov/orgs","repos_url":"https://api.github.com/users/OlegNadymov/repos","events_url":"https://api.github.com/users/OlegNadymov/events{/privacy}","received_events_url":"https://api.github.com/users/OlegNadymov/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-04T12:59:36Z","updated_at":"2016-07-05T06:50:55Z","closed_at":"2016-07-04T16:11:16Z","body":"I found one more bug in Sql.In after update to 4.0.60:\r\n\r\nException text:\r\n```C#\r\nUnhandled expression type: 'Index'\r\n```\r\nMy task: \r\nI want to collect full predicate filter. Therefore I created custom SqlExpression and DialectProvider.\r\nI attached mini example below.\r\n\r\nExceptions raises here:\r\n```C#\r\n_whereExpression = ServiceStack.OrmLite.PredicateBuilder.And(predicate, _whereExpression);\r\n```\r\n\r\nUnit test:\r\n```C#\r\n    public class BaseObject\r\n    {\r\n        public Guid? Identity { get; set; }\r\n    }\r\n\r\n    public class Waybill : BaseObject\r\n    {\r\n        public string Name { get; set; }\r\n    }\r\n\r\n    public class WaybillItem : BaseObject\r\n    {\r\n        public string WbItemName { get; set; }\r\n\r\n        [ForeignKey(typeof (Waybill))]\r\n        public Guid WaybillId { get; set; }\r\n\r\n        [ForeignKey(typeof (MarginItem))]\r\n        public Guid? MarginItemId { get; set; }\r\n    }\r\n\r\n    public class MarginItem : BaseObject\r\n    {\r\n        public string MarginName { get; set; }\r\n    }\r\n\r\n    private class CustomSqlExpression<T> : SqlServerExpression<T>\r\n    {\r\n        private Expression<Func<T, bool>> _whereExpression;\r\n\r\n        public CustomSqlExpression(IOrmLiteDialectProvider dialectProvider) : base(dialectProvider)\r\n        {\r\n        }\r\n\r\n\r\n        public override SqlExpression<T> And(Expression<Func<T, Boolean>> predicate)\r\n        {\r\n            if (_whereExpression == null)\r\n                _whereExpression = predicate;\r\n            else\r\n                _whereExpression = ServiceStack.OrmLite.PredicateBuilder.And(predicate, _whereExpression);//Failed here\r\n\r\n            return base.And(predicate);\r\n        }\r\n    }\r\n\r\n    private class CustomSqlServerDialectProvider : SqlServerOrmLiteDialectProvider\r\n    {\r\n        public override SqlExpression<T> SqlExpression<T>()\r\n        {\r\n            return new CustomSqlExpression<T>(this);\r\n        }\r\n    }\r\n\r\n\r\n    [TestMethod]\r\n    public void CreateSubQuery()\r\n    {\r\n        var db = new OrmLiteConnection(new OrmLiteConnectionFactory(\"test\", new CustomSqlServerDialectProvider()));\r\n\r\n        try\r\n        {\r\n            var expr = db.From<MarginItem>().Where(s => Sql.In(s.Identity,\r\n                db.From<WaybillItem>()\r\n                    .Where(w => Sql.In(w.WaybillId,\r\n                        db.From<Waybill>()\r\n                            .And(bb => bb.Identity == null)\r\n                            .And(bb => bb.Name == \"test\")\r\n                            .Select(ww => ww.Identity))\r\n                    )\r\n                    .Select(b => b.MarginItemId)));\r\n        }\r\n        catch (Exception e)\r\n        {\r\n            Assert.Fail($\"Failed test <{nameof(CreateSubQuery)}>: {e.Message}\");\r\n        }\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/ServiceStack/Issues/issues/comments/230399988","html_url":"https://github.com/ServiceStack/Issues/issues/455#issuecomment-230399988","issue_url":"https://api.github.com/repos/ServiceStack/Issues/issues/455","id":230399988,"user":{"login":"OlegNadymov","id":9961359,"avatar_url":"https://avatars.githubusercontent.com/u/9961359?v=3","gravatar_id":"","url":"https://api.github.com/users/OlegNadymov","html_url":"https://github.com/OlegNadymov","followers_url":"https://api.github.com/users/OlegNadymov/followers","following_url":"https://api.github.com/users/OlegNadymov/following{/other_user}","gists_url":"https://api.github.com/users/OlegNadymov/gists{/gist_id}","starred_url":"https://api.github.com/users/OlegNadymov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OlegNadymov/subscriptions","organizations_url":"https://api.github.com/users/OlegNadymov/orgs","repos_url":"https://api.github.com/users/OlegNadymov/repos","events_url":"https://api.github.com/users/OlegNadymov/events{/privacy}","received_events_url":"https://api.github.com/users/OlegNadymov/received_events","type":"User","site_admin":false},"created_at":"2016-07-05T06:50:55Z","updated_at":"2016-07-05T06:50:55Z","body":"Not, this case don't correctly work. As I say it is mini example (not full).\r\n\r\nIf I add this (in my CustomSqlExpression):\r\n```C#\r\n        public override SqlExpression<T> Where(Expression<Func<T, Boolean>> predicate)\r\n        {\r\n            if (_whereExpression == null)\r\n                _whereExpression = predicate;\r\n            else\r\n                _whereExpression = ServiceStack.OrmLite.PredicateBuilder.And(predicate, _whereExpression); //Failed here\r\n\r\n            return base.Where(predicate);\r\n        }\r\n```\r\n\r\nyour example:\r\n```C#\r\nvar q = db.From<MarginItem>().Where(s => Sql.In(s.Identity,\r\n    db.From<WaybillItem>()\r\n        .Where(w => Sql.In(w.WaybillId,\r\n            db.From<Waybill>()\r\n                .Where(bb => bb.Identity == null) //Always start with Where, before And/Or\r\n                .And(bb => bb.Name == \"test\")\r\n                .Select(ww => ww.Identity))\r\n        )\r\n        .Select(b => b.MarginItemId)));\r\n```\r\nthrows Exception:\r\n```C#\r\nUnhandled expression type: 'Index'\r\n```\r\n\r\nBefore update to 4.0.60 this case worked correctly."}}
{"actor":{"display_login":"OlegNadymov"}}