{"action":"closed","issue":{"url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/67","repository_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql","labels_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/67/comments","events_url":"https://api.github.com/repos/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/67/events","html_url":"https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/67","id":179873226,"number":67,"title":"Weird Behavior with FirstOrDefault","user":{"login":"matthewjcooper","id":1433729,"avatar_url":"https://avatars.githubusercontent.com/u/1433729?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewjcooper","html_url":"https://github.com/matthewjcooper","followers_url":"https://api.github.com/users/matthewjcooper/followers","following_url":"https://api.github.com/users/matthewjcooper/following{/other_user}","gists_url":"https://api.github.com/users/matthewjcooper/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewjcooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewjcooper/subscriptions","organizations_url":"https://api.github.com/users/matthewjcooper/orgs","repos_url":"https://api.github.com/users/matthewjcooper/repos","events_url":"https://api.github.com/users/matthewjcooper/events{/privacy}","received_events_url":"https://api.github.com/users/matthewjcooper/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-28T19:59:47Z","updated_at":"2016-10-04T22:24:05Z","closed_at":"2016-10-04T22:24:05Z","body":"I have a strange issue with using FirstOrDefault. I have the following methods in my generic repository:\r\n\r\n\r\n```\r\n   public TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate)\r\n        {\r\n            return _entities.FirstOrDefault(predicate); // Option 1\r\n            return _entities.Where(predicate).FirstOrDefault(); // Options 2\r\n            return _entities.Where(predicate).ToList().FirstOrDefault(); // Option 3\r\n        }\r\n\r\n     public TEntity SingleOrDefault(Expression<Func<TEntity, bool>> predicate)\r\n        {\r\n            return _entities.SingleOrDefault(predicate);\r\n        }\r\n```\r\n\r\nIf i call the FirstOrDefault method with option 1 or 2  multiple times for different entities, it works the first time, but the second time it just hangs, almost like the first time through never let go of the transaction or something. I don't see any errors, but the system is just stuck and never finishes.\r\n\r\nWhen i use FirstOrDefault with option 3 it works every time just fine. Also, SingleOrDefault does not seem to have this issue.\r\n\r\nHere is the code that is calling it:\r\n\r\n```\r\nvar gender = _unitOfWork.Gender.FirstOrDefault(g => g.Short == viewModel.Gender); \r\n\r\nvar organizationPatientDemographic = _unitOfWork.OrganizationPatientDemographics\r\n                .FirstOrDefault(opd => opd.OrganizationPatientId == session.Visit.OrganizationPatientId);\r\n\r\n```\r\n\r\nThe gender call works, but the demographic call will just hang if using option 1 or 2, but is fine with option 3. And if i swap the order of the calls, demographics works, but gender fails.\r\n\r\nFurther technical details\r\n\r\nMySQL version:  5.7\r\nOperating system: OSX El Capitan\r\nPomelo.EntityFrameworkCore.MySql version: 1.0.0\r\n\r\nI've attached my models, and repositories/unitofwork.\r\n\r\n[Code.zip](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/files/499139/Code.zip)\r\n\r\n"}}
{"actor":{"display_login":"matthewjcooper"}}