Error Adding View in June CTP: CS0104 ColumnAttribute is an Ambiguous Reference
Recently I upgraded to the Entity Framework June 2011 CTP to be able to use Enums in my project model. All went well. Until I needed to add a strongly typed view that wasn’t empty. When trying to create the view I received two errors:
- CS0104 - Compiling transformation: 'ColumnAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.ColumnAttribute' and System.Data.Linq.Mapping.ColumnAttribute’
- CS1061 – Compiling transformation: 'System.ComponentModel.DataAnnotations.ColumnAttribute' does not contain a definition for 'IsPrimaryKey' and no extension method 'IsPrimaryKey' accepting a first argument of type 'System.ComponentModel.DataAnnotations.ColumnAttribute' could be found…
The first error occurs because ColumnAttribute is in both System.ComponentModel.DataAnnotations and System.Data.Linq.Mapping. It is unclear (ambiguous) as to which should be used. I believe that the second error results from the an attempt to use System.ComponentModel.DataAnnotations to create the view which does not contain a definition for IsPrimaryKey. So somehow we need to get Visual Studio to use System.Data.Linq.Mapping instead. After a bit of Googling the following solution presented itself:
Navigate to C:\<Visual Studio Install Path>\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML
Here you will see all the .tt files for Create, Delete, Details, Edit,Empty and List.
You will need to edit all of these files except for Empty.tt
Find the line:
var column = attribute as ColumnAttribute;
Change it to:
var column = attribute as System.Data.Linq.Mapping.ColumnAttribute;
Save and restart Visual Studio. Try and add a view!

6 Comments
John Booty said
You're the best! Worked great. A hearty "thank you" from the other side of the world. :)
Michael Murphy said
Thanks so much for the fix!
Cheers!
Michael
Igor said
That was great! Thanks a million!
I've found out this need to be applied to VB.NET sources as well
Felix said
Thank you, it worked like a charm!
Cleyton Ferrari said
Cool! worked perfectly! Thank you!
Yener Yardim said
Thanks a lot! You have saved my night:)