ef-enum-to-lookup
ef-enum-to-lookup copied to clipboard
Always add schema to SQL statements when creating mapping tables
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
feel free to submit a PR, though make sure you understand the various branches first
see also issue #1