views:

137

answers:

1

I've created a console application focused on C#3.5 and added a reference to System.Web, System.Configuration and Subsonic.Core. Also have in config file

    <?xml version="1.0"?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="UpdateCotswolds.Properties.Settings.Live_IntegraConnectionString" connectionString="Data Source=POSERVER;Initial Catalog=Live_Integra;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

I've then edited Settings.ttinclude

const string Namespace = "Integra.Data";
    const string ConnectionStringName = "UpdateCotswolds.Properties.Settings.Live_IntegraConnectionString";

    //This is the name of your database and is used in naming
    //the repository. By default we set it to the connection string name
    const string DatabaseName = "Live_Integra";

And dragged in the tt files.

When they run I'm getting the error...

Error   2   Running transformation: System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.VisualStudio.TextTemplating47D0892A160210D689C6B90986A9AE0D.GeneratedTextTransformation.LoadTables() in c:\Programming\UpdateCotswolds\UpdateCotswolds\SQLServer.ttinclude:line 134
   at Microsoft.VisualStudio.TextTemplating47D0892A160210D689C6B90986A9AE0D.GeneratedTextTransformation.TransformText() in c:\Programming\UpdateCotswolds\UpdateCotswolds\ActiveRecord.tt:line 23
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)

This is the line in question...

var pkColumn=tbl.Columns.SingleOrDefault(x=>x.Name.ToLower().Trim()==tbl.PrimaryKey.ToLower().Trim());

I'm guessing I'm making a silly mistake and hopefully someone can set me straight...

Thanks in advance...

+1  A: 

It appears that a certain table has more than one primary key? Can you post your schema up? Or maybe your PK and FK are names the exact same and SS is getting confused.

Maybe you can play around with the string[] ExcludeTables = new string[]{}; property found under "Settings.ttinclude" until it works and provide the schema for that one table.

DaveHogan
It's a large schema and we don't own it... is there a way of debugging the tt routine?
Paul D'Ambra
apparently there is http://msdn.microsoft.com/en-us/library/bb126338.aspx#Stepping
Paul D'Ambra
It's not easy :) - Hopefully by now you've found the problem?
DaveHogan
For the scale of the problem I had to go a different route and hard code the DAL. It's only a little tool and not going to be used for much more than a year so was happy to give up on this :)
Paul D'Ambra