This project has moved and is read-only. For the latest updates, please go here.

Sequence contains no matching element


When I run the .tt file in TextTransform (v10 - with .net 4.0) I wind up with this error:
error : Running transformation: System.InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source, Func2 predicate)
at Microsoft.VisualStudio.TextTemplating9fa0732bbbb543eb89ac2e5db145c922.GeneratedTextTransformation.Association.<get_OtherKey>b__34(String o)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
at Microsoft.VisualStudio.TextTemplating9fa0732bbbb543eb89ac2e5db145c922.GeneratedTextTransformation.Association.get_OtherKey()
at Microsoft.VisualStudio.TextTemplating9fa0732bbbb543eb89ac2e5db145c922.GeneratedTextTransformation.TransformText()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)
Any ideas? I'm guessing there's a chance the dbml format has changed since this tool was released?


damieng wrote May 30, 2011 at 5:31 PM

The format almost certainly hasn't changed. Are you sure you have actually saved your DBML file before running it? If so can you please send me your DBML file so I can repro.



tlianza wrote May 31, 2011 at 1:30 AM

I believe I've found the relevant portion of the DBML that's giving the template an issue. Here's a slimmed down sample which will repro - generates fine with sqlmetal, but throws in the text transform.

tlianza wrote Sep 4, 2011 at 5:10 AM

The tweaks I made to resolve this were:
1) On line 330 of L2ST4.ttinclude, changed the OtherKey getter to this (so it could return null, if there are no columns).
get { return (Type.Columns.Count > 0) ? OtherKeyMembers.Select(o => Type.Columns.Single(c => c.Member == o)).ToList() : null; }

2) Then, in the .tt file wrapped the usage of the otherkey property in a null check:
if(association.OtherKey != null){ #>
                     = value.;

Not 100% sure this works properly, but at least allowed me to generate the .cs file.