EF 4自我跟踪实体生成器错误模板不包含NeedsHandleCascade删除方法的定义

时间:2011-04-06 15:01:57

标签: entity-framework-4 t4 self-tracking-entities

尝试使用Visual Studio 2010生成自我跟踪实体时,我收到以下错误:

编译转换:

  

'Microsoft.VisualStudio.TextTemplatingFD3088D2F02A7E80E5DF5FEC4C1DAB39.GeneratedTextTransformation.MetadataTools'   不包含的定义   'NeedsHandleCascadeDeleteMethod'和   没有扩展方法   'NeedsHandleCascadeDeleteMethod'   接受第一个类型的参数   'Microsoft.VisualStudio.TextTemplatingFD3088D2F02A7E80E5DF5FEC4C1DAB39.GeneratedTextTransformation.MetadataTools'   可以找到(你错过了吗?   使用指令或程序集   引用?)

我在其他项目中使用了自我跟踪实体功能,之前没有遇到此问题。我唯一能想到的是我已经将SP1应用于Visual Studio。我需要安装更新的模板,还是应该卸载SP1?

谢谢!

1 个答案:

答案 0 :(得分:1)

我在升级到VS 2010 SP1之前很久就安装了STE模板,但我没有这个问题。

检查NeedsHandleCascadeDeleteMethodEF.Utility.CS.ttinclude的定义。您将在C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes中找到此文件(如果您使用VS的默认安装路径)。该方法应定义如下:

/// <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;
}

同时检查项目中使用的STE模板(实体的部分,而不是上下文的部分)。它只能通过调用:

使用该方法一次
// 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))
{

如果您看到其他任何内容,您的模板可能会以某种方式损坏或您修改它。尝试再次安装。