T4 Templates in Visual Studio 2012 for EF upgrade issue

Category: c# ide

Question

Brian Seekford on Thu, 13 Dec 2012 13:18:03


I have a T4 template we built for EF in Visual Studio 2010 that targeted the 4.0 framework version of EF. I installed VS 2012 and consequently .NET 4.5.

Now, I can't generated my T4 template because it appears to be using the latest EF generator. We fail for 2 reasons. 1, the xml namespaces are different(since it is the newer version). 2, if I change our T4 template to look for the new namespaces, then the build of the assembly fails telling me I am targeting the wrong framework version.

Damned if I do, damned if I don't change the file.

Anyway, Is there a way to tell the T4 scripting engine to target .NET 4.0

I put a partial snippet below to give an example of what we call to generate the edmx data.

snippet:

 

var generator = new EntityStoreSchemaGenerator(this.provider, this.connectionString, ModelNamespace + "." + StoreNamespace);         IList<EdmSchemaError> errors = generator.GenerateStoreMetadata(this.filters);     // Ignore warnings reported for views without primary keys. We are handling them here.     errors = errors.Where(error => error.ErrorCode != 6002).ToList();     this.HandleErrors(errors);     string storageModel = this.GenerateXml(generator.WriteStoreSchema);

Replies

Wyck on Thu, 13 Dec 2012 13:47:34


<#@ template language="C#v4.0" #>

also see: this answer

Brian Seekford on Thu, 13 Dec 2012 14:03:18


I gave that a shot.

The XML generator for EF still emits the newer EF3 namespacing.

<Schema Namespace="Model.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">

I am wondering if there is another setting specific to EF to tell it to generate a specific version.

Brian Seekford on Thu, 13 Dec 2012 14:20:26


Bah. Found an overload at least for the generator now for Version2. Seems to help emit the write XML for that piece.I

I just hope the rest of the generators have that overload.

I appreciate your help with the targeting. I wish there was better documentation on this.