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

Always add schema to SQL statements when creating mapping tables #44

Open
Choc13 opened this issue Jan 21, 2016 · 1 comment
Open

Always add schema to SQL statements when creating mapping tables #44

Choc13 opened this issue Jan 21, 2016 · 1 comment

Comments

@Choc13
Copy link

Choc13 commented Jan 21, 2016

Currently the script that is generated looks something like this:

IF OBJECT_ID('Enum_MyEnum', 'U') IS NULL
begin
    CREATE TABLE [Enum_MyEnum] (Id int CONSTRAINT PK_Enum_MyEnum PRIMARY KEY, Name nvarchar(255));
    exec sys.sp_addextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE',
        @level1name=N'Enum_MyEnum', @value=N'Automatically generated. Contents will be overwritten on app startup. Table & contents generated by https://github.com/timabell/ef-enum-to-lookup';
end

However if the database is not using dbo as the default schema then the exec sys.sp_addextendedproperty statement fails with the error:

Msg 15135, Level 16, State 8, Procedure sp_addextendedproperty, Line 37

Object is invalid. Extended properties are not permitted on 'dbo.Enum_MyEnum', or the object does not exist.

This is because the table Enum_MyEnum does not exist as dbo.Enum_MyEnum. Please could the generated SQL be changed to always explicitly include the schema name, such as:

IF OBJECT_ID('dbo.Enum_MyEnum', 'U') IS NULL
begin
    CREATE TABLE [dbo.Enum_MyEnum] (Id int CONSTRAINT PK_Enum_MyEnum PRIMARY KEY, Name nvarchar(255));
    exec sys.sp_addextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE',
        @level1name=N'Enum_MyEnum', @value=N'Automatically generated. Contents will be overwritten on app startup. Table & contents generated by https://github.com/timabell/ef-enum-to-lookup';
end
@timabell
Copy link
Owner

feel free to submit a PR, though make sure you understand the various branches first

see also issue #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants