Closed R-Norman closed 2 years ago
Interesting... I'll give it some thought :-)
Change the following function so it returns the right SQL query you need for your tables:
protected override string EnumSQL(string table, string nameField, string valueField)
{
return string.Format("SELECT {0} as NameField, {1} as ValueField, * FROM {2};", nameField, valueField, table);
}
To something like this:
protected override string EnumSQL(string table, string nameField, string valueField)
{
if(table.Equals("dbo.SomeTable", StringComparison.InvariantCultureIgnoreCase))
return string.Format("SELECT todo;", nameField, valueField, table);
if(table.Equals("dbo.AnotherTable", StringComparison.InvariantCultureIgnoreCase))
return string.Format("SELECT todo;", nameField, valueField, table);
return string.Format("SELECT {0} as NameField, {1} as ValueField, * FROM {2};", nameField, valueField, table);
}
Closing this issue. If the above does not work, please add a comment and I will re-open.
I am assuming the code you suggested goes into ttinclude file? I could not get that to work. There are two methods that have code in them and I even tried to break them by messing up the SQL but the existing enums were still generated normally.
However, I was able to get this working with a hack using simple SQL injection :)
Table = "dbo.TableForEnum WHERE TypeId=1",
Please do not "fix" this until another way is confirmed or added :) Ideally, injection should not be allowed anywhere. The addition of a "WHERE" clause parameter might be the simplest way to support the same functionality without injection.
Yes, the above was for a change to the .ttinclude file. I won't be adding this as permanent feature unless other people also want this, and I can get it to work in a simple common sense way for everyone. I'm glad you got something working.
Is there a way to filter the data used for an enum (not all rows)? If not, please add the ability to filter which rows are used for enum generation. In my use case, the filter needs to use a column not included in the enum itself. This could be a DB where or maybe a callback that can include additional rows to evaluate.
Basically, I have a large table that has data for multiple applications and really only want data for one at a time as enums.
For now, I will continue to code this specific enum manually (or maybe create app specific views just for this generation in the DB).
Thanks