0

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.

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

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

// Not interested in below
{
    SetOrdianls(reader);
}

while (reader.HasRows())
{
    returnCollection.Add(new Entity(reader);
}

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

The ordinals are simply static integer values refering to a location in some DataReader results. They are set using the SetOrdinals(DataReader reader) method.

Thanks Anthony

Ant Swift
  • 20,089
  • 10
  • 38
  • 55
  • I think you're not getting answers because your question isn't clear. We don't know what ordinal_etcs are or what -1 means in this case. Perhaps more details about what you're trying to do rather than the code? –  Dec 02 '09 at 16:04
  • Question is unclear, not enough detail – Maslow Dec 19 '09 at 15:34
  • I know its late but I've modified the question to include more information and description. – Ant Swift Jul 19 '11 at 12:20

1 Answers1

0

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

Ant Swift
  • 20,089
  • 10
  • 38
  • 55