Search code examples
entity-frameworkentity-framework-4.1pocot4edmx

Using T4 to generate Poco classes, ignores the StoreGeneratedPattern attribute


I'm using the Poco & DbContext T4 template in vs 2010 to generate the pocos for my data access, i've modified it to match some syntax required by my data access layer.

I've one problem that, the identity column (StoreGeneratedPattern = Identity) in the edmx file dosn't affect the T4 generating process, here is my code for it:

var identity = edmProperty.TypeUsage.Facets.Where(f => f.Name == "StoreGeneratedPattern").FirstOrDefault();
        if (identity != null && ((System.Data.Metadata.Edm.StoreGeneratedPattern)identity.Value) == System.Data.Metadata.Edm.StoreGeneratedPattern.Identity)
                    isIdentity = true;

this is always be false , is there a any reason for this?


Solution

  • StoreGeneratedPattern is not stored in facets but in MetadataProperties try something like this:

    var identity = edmProperty.MetadataProperties
                              .Where(m => m.Name == "http://schemas.microsoft.com/ado/2009/02/edm/annotation:StoreGeneratedPattern")
                              .FirstOrDefault();
    
    bool isIdentity = identity != null && identity.Value == System.Data.Metadata.Edm.StoreGeneratedPattern.Identity.ToString();