{"action":"created","issue":{"url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513","repository_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL","labels_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513/comments","events_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513/events","html_url":"https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513","id":340216266,"node_id":"MDU6SXNzdWUzNDAyMTYyNjY=","number":513,"title":"MapEnum in Context fails with Migrations","user":{"login":"Systemdir","id":4005451,"node_id":"MDQ6VXNlcjQwMDU0NTE=","avatar_url":"https://avatars1.githubusercontent.com/u/4005451?v=4","gravatar_id":"","url":"https://api.github.com/users/Systemdir","html_url":"https://github.com/Systemdir","followers_url":"https://api.github.com/users/Systemdir/followers","following_url":"https://api.github.com/users/Systemdir/following{/other_user}","gists_url":"https://api.github.com/users/Systemdir/gists{/gist_id}","starred_url":"https://api.github.com/users/Systemdir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Systemdir/subscriptions","organizations_url":"https://api.github.com/users/Systemdir/orgs","repos_url":"https://api.github.com/users/Systemdir/repos","events_url":"https://api.github.com/users/Systemdir/events{/privacy}","received_events_url":"https://api.github.com/users/Systemdir/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-11T12:16:00Z","updated_at":"2018-07-16T15:41:10Z","closed_at":"2018-07-16T15:41:10Z","author_association":"NONE","body":"I have the issue that when calling MapEnum \r\n(`NpgsqlConnection.GlobalTypeMapper.MapEnum<T>(typeof(T).Name.ToLower())`)\r\nin the Context before migrating (`context.Database.Migrate();`), the enum type on successive requests is not found. This happens even when MapEnum is called again after the migration.\r\n\r\n    2018-07-11 13:26:42.2283 | ERROR | Update | An exception occurred in the database while saving changes for context type 'Clt.Atmentis.Data.Context.AtmentisContext'.\r\n    Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.NotSupportedException: The CLR enum type Gender must be registered with Npgsql before usage, please refer to the documentation.\r\n    at Npgsql.TypeMapping.ConnectorTypeMapper.GetByClrType(Type type) in /home/roji/projects/npgsql/src/Npgsql/TypeMapping/ConnectorTypeMapper.cs:line 143\r\n    at Npgsql.NpgsqlParameter.ResolveHandler(ConnectorTypeMapper typeMapper) in /home/roji/projects/npgsql/src/Npgsql/NpgsqlParameter.cs:line 529\r\n    at Npgsql.NpgsqlCommand.ValidateParameters() in /home/roji/projects/npgsql/src/Npgsql/NpgsqlCommand.cs:line 796\r\n    at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in /home/roji/projects/npgsql/src/Npgsql/NpgsqlCommand.cs:line 1141\r\n    at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in /home/roji/projects/npgsql/src/Npgsql/NpgsqlCommand.cs:line 1130\r\n    at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)\r\n    at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)\r\n    at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n\r\n**Current Workarround**\r\nI am now calling MapEnum not in the context but only once after running the migrations.\r\n      \r\n    context.Database.Migrate();\r\n    context.PgsqlEnumMappings();\r\n    // successive requests ...\r\n\r\n**Further technical details**\r\n\r\nEnityFramework version: Microsoft.AspNetCore.Identity.EntityFrameworkCore v2.1.2\r\nNpgsql version: Npgsql.EntityFrameworkCore.PostgreSQL v2.1.1\r\nPostgreSQL version: PostgreSQL 10.3 (Debian 10.3-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit\r\nOperating system: (Docker) Debian GNU/Linux 9"},"comment":{"url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/comments/405290695","html_url":"https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513#issuecomment-405290695","issue_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/513","id":405290695,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTI5MDY5NQ==","user":{"login":"Systemdir","id":4005451,"node_id":"MDQ6VXNlcjQwMDU0NTE=","avatar_url":"https://avatars1.githubusercontent.com/u/4005451?v=4","gravatar_id":"","url":"https://api.github.com/users/Systemdir","html_url":"https://github.com/Systemdir","followers_url":"https://api.github.com/users/Systemdir/followers","following_url":"https://api.github.com/users/Systemdir/following{/other_user}","gists_url":"https://api.github.com/users/Systemdir/gists{/gist_id}","starred_url":"https://api.github.com/users/Systemdir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Systemdir/subscriptions","organizations_url":"https://api.github.com/users/Systemdir/orgs","repos_url":"https://api.github.com/users/Systemdir/repos","events_url":"https://api.github.com/users/Systemdir/events{/privacy}","received_events_url":"https://api.github.com/users/Systemdir/received_events","type":"User","site_admin":false},"created_at":"2018-07-16T15:41:09Z","updated_at":"2018-07-16T15:41:09Z","author_association":"NONE","body":"I managed to solve the issue by thowing away the migrations and recreating them with the correct mappings.\r\n\r\nIn order to migrate, I now call following method on my db context:\r\n\r\n    public void Migrate()\r\n    {\r\n         Database.Migrate();\r\n            \r\n         // reload enumn mappings\r\n         NpgsqlConnection npgsqlConnection = ((NpgsqlConnection) Database.GetDbConnection());\r\n         npgsqlConnection.Open();\r\n         npgsqlConnection.ReloadTypes();\r\n    }\r\n\r\nThank you for your help!"}}
{"actor":{"display_login":"Systemdir"}}