-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I get errors when performing reverse engineering of my database and do not know because it is produced #3861
Comments
@micball Thanks for reporting this. The initial SqlNullException is a bug - we should fix that. Could you share your database schema including table and index definitions and any statements creating the primary, alternate and foreign keys (if separate) to help us track down what is causing it? Also could you include the version of SQL Server you're working with? The other messages are warnings rather than errors. The ones of the form The ones that start with |
Thank you for your help, my sql versión is: Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64) Attach scripts for replicate database, they must be executed in the order. |
@micball. I am unable to apply scripts 2 onwards because they reference schema [Maldivas_base] which has not been defined. And I was unable to reproduce the However even with just script 1 I could analyze some of the issue:
In this case
Parentheses are ignored but the quotes are important for string-like columns. Unfortunately SQL Server does not stop you putting incorrect values in the default at definition-time. You only find out when you attempt to use the default (or in our case read metadata about the default). The warnings of the form |
As a faster way of diagnosing the
|
Hi lajones, thank you very much for your help, I have corrected the names duplicates of the foreign keys and I have reviewed all my defaults used the following query: SELECT 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, Finally I created a new project and model and receive the next error: Scaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -connection "Server=Sealand;Database=Maldivas_test;Trusted_Connection=True;" Attach update file. |
@micball The second error indicates that our code is trying to create an index on a table that it doesn't know about. I could do with the results of the query I mentioned before - that's the query we run to look for the index columns. Plus, rather than changing your schema, I would like to try to figure out what is happening - so I can harden our code against database metadata which is incorrect and issue more helpful error messages. Also re your query for default values - the line |
@lajones, when execute the query of (SqlNullValueException) I see the next line index_name schema_name table_name is_unique column_name type_desc I understand that this is because the table has a defined partition on the field ( fecha_entrada ] ) Note: The partitions is only avaible in enterprise versions of Sql Server However, when the script is generated i dont see the code of the partition, only the last line show Attach query result of indexes |
I think the main problem is that the generator does not display the information with the name of the tables, fields, indexes or relationships that produce this errors. The query of the default zero value is omitted because I use to configure my system metadata in own entities. |
I run the next querys for incorrect default values in numeric fields SELECT 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, SELECT 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, |
I send the updated script after deleting the partition, rename the names of the relations and update erroneous default values. 1 - Maldivas Test - Create Schemas Tables and Index.txt Attach query with diagnosing the SqlNullValueException When execute again with the update model... Console return: |
@micball I was unable to repro the |
PR #3934 checked in with commit 454968a. As I mentioned I couldn't repro it, but I've put in guard code which should guard against all of the situations you were seeing above plus fix the issue with confusing the 2 indexes with the same name but different schemas. This should be available in tonight's nightly build. |
Lagones thank you very much for your work, I would like to add two interesting points that you could use to improve EF , one is referring to the name of the tables and entities and this has caused me some problems, it may be the case according to the security scheme you can find two tables with the same name, index and relations, for example : Table 1 schema buy, Table 2 Schema sell Both tables have the same name, same name even indices in relationships and certainly create some error. I understand that to solve this the name of the entities, index and relationships should be Schema Name + Table Name + Index Name or Relation Name, etc. Another detected error that we have not talked about is the reference to the XML field type is Regarding duplicate indexes you can use the following statement ;WITH MyDuplicate AS (SELECT As you can see, I'll have to rename a few ... attach image. |
@micball Re the xml data type - that issue is already tracked in issue #3076. Re naming entity types to include their schema - this has been discussed in the past (as was the idea of converting the schema into the C# namespace) and we decided not to do it. Instead we decided just to name the first entity type e.g. Other duplicates should now just work. E.g. having 2 indexes which only differ by schema should now work with no renaming required on your end. It was just a bug in our code that wasn't distinguishing them. |
Also best response for the warnings of the form: "For 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." is to change the data type in the schema to something a bit bigger e.g. |
In new console project run nugget console:
Install-Package EntityFramework.MicrosoftSqlServer –Pre
Install-Package EntityFramework.Commands –Pre
Install-Package EntityFramework.MicrosoftSqlServer.Design –Pre
Finaly execute:
Scaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -connection "Server=Sealand;Database=Maldivas_oran;Trusted_Connection=True;"
The first test show:
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at System.Data.SqlClient.SqlBuffer.get_String()
at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at Microsoft.Data.Entity.Scaffolding.SqlServerDatabaseModelFactory.GetIndexes()
at Microsoft.Data.Entity.Scaffolding.SqlServerDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.SqlServerScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
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)at Microsoft.Data.Entity.Design.OperationExecutor.d__19.MoveNext()
at System.Linq.Buffer
1..ctor(IEnumerable
1 source)at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source) at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0
1.b__0()at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)
Data is Null. This method or property cannot be called on Null values.
Some 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'
Another test with empty database result:
Unable to interpret the string 1 as a SQLServer string literal.
Could not find type mapping for column 'General.Incidencias.Configuracion' with data type 'xml'. Skipping column.
Unable to interpret the string 111 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 1 as a SQLServer string literal.
For 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.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Unable to interpret the string 0 as a SQLServer string literal.
Could 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'.
Could 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'.
Could 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'.
Could 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'.
Could 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'.
Could 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'.
Could 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'.
The text was updated successfully, but these errors were encountered: