views:

86

answers:

1

I'm new to T4 but I have stumbled accross it and it looks very useful.

I'm trying to generate some simple DA classes and need some advice one a particular part of my code.

Hoe can i generate the following code given that I already have the table name and column names (in this case "Agreements" and "AgreementId", "ContactId", etc)?

if (
(ordinal_TableName_ColumnName1 == -1)
|| (ordinal_TableName_ColumnName2 == -1)
|| (ordinal_TableName_ColumnName3 == -1)
|| (ordinal_TableName_ColumnName4 == -1)
)

The -1 figure is the default value and the cause the condition to fail.

Thanks Anthony

A: 

Figured the answer out.

for(int i = 0; i < table.Columns.Count; i++)
{
    Write(string.Format("(ordinal_{0}_{1}.HasValue)", table.Name, table.Columns[i].Name));
    if(i < (table.Columns.Count - 1))
    {
        WriteLine(" ||");
    }
}

Thanks, Ant

Anthony