EF 4 自跟踪实体生成器错误模板不包含 NeedsHandleCascadeDeleteMethod 的防御

发布于 2024-10-31 02:24:16 字数 563 浏览 4 评论 0原文

当尝试使用 Visual Studio 2010 生成自跟踪实体时,出现以下错误:

编译转换:

“Microsoft.VisualStudio.TextTemplateFD3088D2F02A7E80E5DF5FEC4C1DAB39.GenerateTextTransformation.MetadataTools” 不包含以下定义 'NeedsHandleCascadeDeleteMethod' 和 没有扩展方法 '需要HandleCascadeDelete方法' 接受类型的第一个参数 'Microsoft.VisualStudio.TextTemplateFD3088D2F02A7E80E5DF5FEC4C1DAB39.GenerateTextTransformation.MetadataTools' 可以找到(您是否缺少 using 指令或程序集 参考?)

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-11-07 02:24:16

我在升级到 VS 2010 SP1 之前安装了 STE 模板很长时间,但没有遇到此问题。

检查EF.Utility.CS.ttincludeNeedsHandleCascadeDeleteMethod的定义。您将在 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))
{

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文