Skip to content
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

Reverse engineering: SQL Server User Defined Data Type cannot be reverse engineered #7576

Closed
Axioma-ShirokovPN opened this issue Feb 9, 2017 · 6 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@Axioma-ShirokovPN
Copy link

If we have some schemas with identical name of UDDT - we get error
System.ArgumentException: An item with the same key has already been added. Key: TypeId

Steps to reproduce

Create 2 schemas: Items, Users.
Create 2 UDDT: Items.TypeId (tinyint), Users.TypeId (tinyint)

After this, call:
Scaffold-DbContext "Server=localhost\SQLEXPRESS; Database=SimpleDB; User Id=Test; Password=Test; MultipleActiveResultSets=true;" Microsoft.EntityFrameworkCore.SqlServer -Force -Verbose
And you will receive:
System.ArgumentException: An item with the same key has already been added. Key: TypeId
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerDatabaseModelFactory.GetTypeAliases() at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, TableSelectionSet tableSelectionSet) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet) at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext() at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source, Int32& length)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
An item with the same key has already been added. Key: TypeId

Why I can't have 2 UDDT with the same name in different schemas?

Further technical details

@ajcvickers
Copy link
Contributor

Not sure if this is a dupe, but looks like the same scenario as #7315.

@lajones
Copy link
Contributor

lajones commented Feb 10, 2017

@ajcvickers I think this is a separate bug. In SqlServerDatabaseModelFactory the query which brings back the type aliases does not include their schema. Don't think it ever did, but it looks like it should to support the above scenario. #7315 is about failing to receive warnings which should be there. I haven't investigated yet, but we used to produce warnings, so either the situation in #7315 is somehow different from the situation where we do produce warnings, or the warnings have been mistakenly removed, or somehow the work we did on logging levels has meant they no longer display.

@Axioma-ShirokovPN
Copy link
Author

Yes, this is separate bug, but from one category - incorrect work with UDDT.

@lajones
Copy link
Contributor

lajones commented Apr 12, 2017

Fixed with commits 0993e23 and caa6dce.

@lajones lajones closed this as completed Apr 12, 2017
@lajones lajones added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 12, 2017
@Axioma-ShirokovPN
Copy link
Author

I try to test it again with aspnet-1-1-2-may2017-patch-public and it not works.
I have many UDDT with name TypeId, but in different schemas and I have the same error:
An item with the same key has already been added. Key: TypeId

@lajones
Copy link
Contributor

lajones commented Apr 27, 2017

@Axioma-ShirokovPN I'm afraid the fix for this only went into the 2.0.0 release, not the 1.1.2 release. So it is not available in the aspnet-1-1-2-may2017-patch-public feed.

@ajcvickers ajcvickers changed the title Scaffold-DbContext, MSSQL User Defined Data Type can't reverse types Reverse engineering: SQL Server User Defined Data Type cannot be reverse engineered May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants