2

When trying to generate self-tracking entities using Visual Studio 2010 I am getting the following error:

Compiling transformation:

'Microsoft.VisualStudio.TextTemplatingFD3088D2F02A7E80E5DF5FEC4C1DAB39.GeneratedTextTransformation.MetadataTools' does not contain a definition for 'NeedsHandleCascadeDeleteMethod' and no extension method 'NeedsHandleCascadeDeleteMethod' accepting a first argument of type 'Microsoft.VisualStudio.TextTemplatingFD3088D2F02A7E80E5DF5FEC4C1DAB39.GeneratedTextTransformation.MetadataTools' could be found (are you missing a using directive or an assembly reference?)

I have used the self-tracking entities feature on other projects and have not had this problem before. The only thing I can think of is that I have applied SP1 to Visual Studio. Is there an updated template I need to install or should I just uninstall SP1?

Thanks!

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
Andrew
  • 165
  • 1
  • 6

1 Answers1

1

I installed STE template long time before I upgraded to VS 2010 SP1 and I don't have this issue.

Check the definition of NeedsHandleCascadeDeleteMethod in EF.Utility.CS.ttinclude. You will find this file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes (if you used default installation path for VS). The method should be defined like:

/// <summary>
/// True if this entity type requires the HandleCascadeDelete method defined and the method has
/// not been defined on any base type
/// </summary>
public bool NeedsHandleCascadeDeleteMethod(ItemCollection itemCollection, EntityType entity)
{
    bool needsMethod = ContainsCascadeDeleteAssociation(itemCollection, entity);
    // Check to make sure no base types have already declared this method
    EntityType baseType = entity.BaseType as EntityType;
    while(needsMethod && baseType != null)
    {
        needsMethod = !ContainsCascadeDeleteAssociation(itemCollection, baseType);
        baseType = baseType.BaseType as EntityType;
    }
    return needsMethod;
}

Also check your STE template used in the project (the part for entities, not the part for context). It should use the method only once by calling:

// If this entity type participates in any relationships where the other end has an OnDelete
// cascade delete defined, or if it is the dependent in any identifying relationships, it needs
// an event handler to handle notifications that are fired when the parent is deleted.
if (ef.NeedsHandleCascadeDeleteMethod(ItemCollection, entity))
{

If you see anything else your template is probably somehow corrupted or you modified it. Try to install it again.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I checked the template and the one I have does not have the method as described above. Therefore, I uninstalled my copy of VS using the uninstall tool provided by Microsoft (not the one with VS). I also deleted the VS 10.0 folders as described above, then I re-installed VS. The newly installed template still does not have the method mentioned above. We have a volume license with Microsoft and I am using VS 2010 Ultimate version 10.0.20219.1 RTMRel. I found out that there is an SP1 for VS Ultimate but I decided not to try and install it right now since I am under a deadline. – Andrew Apr 13 '11 at 14:02