2011-04-06 40 views
2

當試圖生成自跟蹤實體使用Visual Studio 2010,我收到以下錯誤:EF 4自跟蹤實體生成錯誤模板不包含Defenition爲NeedsHandleCascadeDeleteMethod

編譯轉型:

'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?)

我已經在其他項目上使用了自我追蹤實體功能,並且之前沒有遇到過這個問題。我唯一能想到的是我已經將SP1應用於Visual Studio。是否有需要安裝的更新模板,或者我應該只卸載SP1?

謝謝!

回答

1

我在升級到VS 2010 SP1之前很長時間安裝了STE模板,並且我沒有這個問題。

檢查的定義在EF.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)) 
{ 

,或者你修改了它:它應該通過調用使用的方法只有一次。嘗試再次安裝它。

+0

我檢查了模板,我沒有如上所述的方法。因此,我使用微軟提供的卸載工具卸載了我的VS副本(而不是VS版本)。我也如上所述刪除了VS 10.0文件夾,然後我重新安裝了VS.新安裝的模板仍然沒有上述方法。我們擁有微軟的批量許可證,我使用VS 2010 Ultimate版本10.0.20219.1 RTMRel。我發現有一個VS Ultimate的SP1,但我決定現在不要嘗試安裝它,因爲我在最後期限之內。 – Andrew 2011-04-13 14:02:24

+0

然而,你指出我正確的方向。謝謝! – Andrew 2011-04-13 14:02:50