{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13179","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13179/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13179/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13179/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13179","id":356069925,"node_id":"MDU6SXNzdWUzNTYwNjk5MjU=","number":13179,"title":"Indices with conversions defined should perform comparison in db on converted value","user":{"login":"mqudsi","id":606923,"node_id":"MDQ6VXNlcjYwNjkyMw==","avatar_url":"https://avatars3.githubusercontent.com/u/606923?v=4","gravatar_id":"","url":"https://api.github.com/users/mqudsi","html_url":"https://github.com/mqudsi","followers_url":"https://api.github.com/users/mqudsi/followers","following_url":"https://api.github.com/users/mqudsi/following{/other_user}","gists_url":"https://api.github.com/users/mqudsi/gists{/gist_id}","starred_url":"https://api.github.com/users/mqudsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mqudsi/subscriptions","organizations_url":"https://api.github.com/users/mqudsi/orgs","repos_url":"https://api.github.com/users/mqudsi/repos","events_url":"https://api.github.com/users/mqudsi/events{/privacy}","received_events_url":"https://api.github.com/users/mqudsi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-31T17:47:10Z","updated_at":"2018-09-04T22:33:34Z","closed_at":null,"author_association":"NONE","body":"Given a class with an index set up pointing to a value (of any type) that has a conversion defined, the index comparison should be performed on the converted value in the database and should not rely on the availability of `IEquatable<Foo>`. \r\n\r\nI could probably file a separate bug for this, but additionally, if `IEquatable<Foo>` is required and `Foo` is `Nullable<T> where T: IEquatable<T>`, EF Core should be able to deduce the comparison between the two `Foo` instances.\r\n\r\nAttempting to compile and run the code at the end of this PR results in an exception on the call to `db.SaveChanges()` which complains that `The binary operator Equal is not implemented for the types System.Nullable<SocialSecurityNumber> and System.Nullable<SocialSecurityNumber>`\r\n\r\nThe stack trace is not helpful and is besides the point, but in all cases:\r\n\r\n```\r\nException thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.Data.Sqlite.dll\r\nException thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.EntityFrameworkCore.Relational.dll\r\nException thrown: 'System.InvalidOperationException' in System.Linq.Expressions.dll\r\nException thrown: 'System.Reflection.TargetInvocationException' in System.Private.CoreLib.dll\r\nException thrown: 'System.InvalidOperationException' in Microsoft.EntityFrameworkCore.dll\r\nAn unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.EntityFrameworkCore.dll\r\n```\r\n\r\n### Further technical details\r\nEF Core version: 2.1.2\r\nDatabase Provider: Sqlite 2.1.2\r\nOperating system: Windows 10, N/A\r\nIDE: N/A\r\n\r\n### Code\r\n\r\n```csharp\r\nnamespace EFCoreNullTest\r\n{\r\n    public struct SocialSecurityNumber : IEquatable<SocialSecurityNumber>\r\n    {\r\n        public int Number { get; set; }\r\n\r\n        public bool Equals(SocialSecurityNumber other)\r\n        {\r\n            return Number == other.Number;\r\n        }\r\n    }\r\n\r\n    public class Person\r\n    {\r\n        public int Id { get; set; }\r\n        public string Name { get; set; }\r\n        public SocialSecurityNumber? SSN { get; set; }\r\n    }\r\n\r\n    class Database : DbContext\r\n    {\r\n        public Database(DbContextOptions options)\r\n            : base(options)\r\n        { }\r\n\r\n        protected override void OnModelCreating(ModelBuilder builder)\r\n        {\r\n            base.OnModelCreating(builder);\r\n\r\n            builder.Entity<Person>()\r\n                .Property(p => p.SSN)\r\n                .HasConversion(ssn => ssn.HasValue ? ssn.Value.Number : new int?(),\r\n                i => i.HasValue ? new SocialSecurityNumber { Number = i.Value } : new SocialSecurityNumber?());\r\n            builder.Entity<Person>()\r\n                .HasIndex(p => p.SSN)\r\n                .IsUnique();\r\n        }\r\n    }\r\n\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            var dbOptions = new DbContextOptionsBuilder().UseSqlite(\"Data Source=test.db\");\r\n            var db = new Database(dbOptions.Options);\r\n            db.Database.EnsureCreated();\r\n\r\n            db.Add(new Person()\r\n            {\r\n                Name = \"John Doe\"\r\n            });\r\n\r\n            db.SaveChanges();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/418539380","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/13179#issuecomment-418539380","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/13179","id":418539380,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODUzOTM4MA==","user":{"login":"ajcvickers","id":1430078,"node_id":"MDQ6VXNlcjE0MzAwNzg=","avatar_url":"https://avatars1.githubusercontent.com/u/1430078?v=4","gravatar_id":"","url":"https://api.github.com/users/ajcvickers","html_url":"https://github.com/ajcvickers","followers_url":"https://api.github.com/users/ajcvickers/followers","following_url":"https://api.github.com/users/ajcvickers/following{/other_user}","gists_url":"https://api.github.com/users/ajcvickers/gists{/gist_id}","starred_url":"https://api.github.com/users/ajcvickers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajcvickers/subscriptions","organizations_url":"https://api.github.com/users/ajcvickers/orgs","repos_url":"https://api.github.com/users/ajcvickers/repos","events_url":"https://api.github.com/users/ajcvickers/events{/privacy}","received_events_url":"https://api.github.com/users/ajcvickers/received_events","type":"User","site_admin":false},"created_at":"2018-09-04T22:33:34Z","updated_at":"2018-09-04T22:33:34Z","author_association":"MEMBER","body":"@mqudsi Can you post the full stack trace?"}}
{"actor":{"display_login":"ajcvickers"}}