{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3861","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3861/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3861/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3861/events","html_url":"https://github.com/aspnet/EntityFramework/issues/3861","id":118486353,"number":3861,"title":"I get errors when performing reverse engineering of my database and do not know because it is produced","user":{"login":"micball","id":4987574,"avatar_url":"https://avatars.githubusercontent.com/u/4987574?v=3","gravatar_id":"","url":"https://api.github.com/users/micball","html_url":"https://github.com/micball","followers_url":"https://api.github.com/users/micball/followers","following_url":"https://api.github.com/users/micball/following{/other_user}","gists_url":"https://api.github.com/users/micball/gists{/gist_id}","starred_url":"https://api.github.com/users/micball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micball/subscriptions","organizations_url":"https://api.github.com/users/micball/orgs","repos_url":"https://api.github.com/users/micball/repos","events_url":"https://api.github.com/users/micball/events{/privacy}","received_events_url":"https://api.github.com/users/micball/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/1%20-%20Working","name":"1 - Working","color":"CCCCCC"},{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/pri0","name":"pri0","color":"e11d21"}],"state":"open","locked":false,"assignee":{"login":"lajones","id":1915927,"avatar_url":"https://avatars.githubusercontent.com/u/1915927?v=3","gravatar_id":"","url":"https://api.github.com/users/lajones","html_url":"https://github.com/lajones","followers_url":"https://api.github.com/users/lajones/followers","following_url":"https://api.github.com/users/lajones/following{/other_user}","gists_url":"https://api.github.com/users/lajones/gists{/gist_id}","starred_url":"https://api.github.com/users/lajones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lajones/subscriptions","organizations_url":"https://api.github.com/users/lajones/orgs","repos_url":"https://api.github.com/users/lajones/repos","events_url":"https://api.github.com/users/lajones/events{/privacy}","received_events_url":"https://api.github.com/users/lajones/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7","html_url":"https://github.com/aspnet/EntityFramework/milestones/7.0.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"7.0.0","description":"","creator":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"open_issues":252,"closed_issues":23,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2015-11-26T07:50:37Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2015-11-23T22:20:19Z","updated_at":"2015-11-26T11:23:17Z","closed_at":null,"body":"In new console project run nugget console:\r\n\r\nInstall-Package EntityFramework.MicrosoftSqlServer –Pre\r\nInstall-Package EntityFramework.Commands –Pre\r\nInstall-Package EntityFramework.MicrosoftSqlServer.Design –Pre\r\n\r\nFinaly execute:\r\n\r\nScaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -connection \"Server=Sealand;Database=Maldivas_oran;Trusted_Connection=True;\"\r\n\r\nThe first test show:\r\n\r\nSystem.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.\r\n   at System.Data.SqlClient.SqlBuffer.get_String()\r\n   at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)\r\n   at Microsoft.Data.Entity.Scaffolding.SqlServerDatabaseModelFactory.GetIndexes()\r\n   at Microsoft.Data.Entity.Scaffolding.SqlServerDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)\r\n   at Microsoft.Data.Entity.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)\r\n   at Microsoft.Data.Entity.Scaffolding.SqlServerScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)\r\n   at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)\r\n   at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)\r\n   at Microsoft.Data.Entity.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, List`1 schemas, List`1 tables, Boolean useDataAnnotations, CancellationToken cancellationToken)\r\n   at Microsoft.Data.Entity.Design.OperationExecutor.<ReverseEngineerImpl>d__19.MoveNext()\r\n   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n   at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()\r\n   at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)\r\nData is Null. This method or property cannot be called on Null values.\r\n\r\n\r\nSome key columns in different tables has same name by example, the key name in table 'ivas' is 'codigo', the keyname in table 'albaranes' is 'codigo' \r\n\r\nAnother test with empty database result:\r\n\r\nUnable to interpret the string 1 as a SQLServer string literal.\r\nCould not find type mapping for column 'General.Incidencias.Configuracion' with data type 'xml'. Skipping column.\r\nUnable to interpret the string 111 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 1 as a SQLServer string literal.\r\nFor column Financiera.Cartera_estados.Codigo. This column is set up as an Identity column, but the SQL Server data type is tinyint. This will be mapped to CLR type byte which does not allow the SqlServerValueGenerationStrategy.IdentityColumn setting. Generating a matching Property but ignoring the Identity setting.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nUnable to interpret the string 0 as a SQLServer string literal.\r\nCould not scaffold the foreign key 'Compras.Compras_albaranes_cabecera(Iva,Iva)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Ivas'.\r\nCould not scaffold the foreign key 'Compras.Compras_facturas_detalle(Codigo,Codigo)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Compras_facturas_cabecera'.\r\nCould not scaffold the foreign key 'Ventas.Ventas_albaranes_cabecera(Forma_pago,Forma_pago)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Formas_pago'.\r\nCould not scaffold the foreign key 'Compras.Compras_pedidos_detalle(Almacen,Almacen)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Almacen'.\r\nCould not scaffold the foreign key 'Compras.Compras_proformas_detalle(Articulo,Articulo)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Articulos'.\r\nCould not scaffold the foreign key 'Compras.Compras_proformas_detalle(Codigo,Codigo)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Compras_proformas_cabecera'.\r\nCould not scaffold the foreign key 'Ventas.Ventas_pedidos_detalle(Iva,Iva)'. A key for 'Codigo,Codigo' was not found in the principal entity type 'Ivas'."},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/159888931","html_url":"https://github.com/aspnet/EntityFramework/issues/3861#issuecomment-159888931","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3861","id":159888931,"user":{"login":"micball","id":4987574,"avatar_url":"https://avatars.githubusercontent.com/u/4987574?v=3","gravatar_id":"","url":"https://api.github.com/users/micball","html_url":"https://github.com/micball","followers_url":"https://api.github.com/users/micball/followers","following_url":"https://api.github.com/users/micball/following{/other_user}","gists_url":"https://api.github.com/users/micball/gists{/gist_id}","starred_url":"https://api.github.com/users/micball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micball/subscriptions","organizations_url":"https://api.github.com/users/micball/orgs","repos_url":"https://api.github.com/users/micball/repos","events_url":"https://api.github.com/users/micball/events{/privacy}","received_events_url":"https://api.github.com/users/micball/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T11:23:17Z","updated_at":"2015-11-26T11:23:17Z","body":"I run the next query for incorrect default values in numeric fields\r\n\r\nSELECT TOP 100 PERCENT SCHEMA_NAME(t.schema_id) AS SchemaName, t.name AS TableName, RTRIM(SCHEMA_NAME(t.schema_id)) + '.' + RTRIM(t.name) AS FullName,\r\n c.name AS ColumnName, tp.name as DataType, object_definition(c.default_object_id) AS ValueColumn\r\n FROM sys.tables AS t\r\n INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID\r\n INNER JOIN sys.objects o ON o.object_id = c.object_id\r\n INNER JOIN sys.types tp ON c.system_type_id = tp.system_type_id\r\n WHERE object_definition(c.default_object_id) IS NOT NULL\r\n\r\n and object_definition(c.default_object_id) = '((0))' AND tp.name not in ('smallint', 'money', 'decimal', 'int', 'bit', 'tinyint', 'smallmoney', 'numeric', 'float', 'bigint')\r\n![errors in default values](https://cloud.githubusercontent.com/assets/4987574/11421969/7708bb34-9438-11e5-83e0-005556535a5a.JPG)\r\n"}}