我在升级到 VS 2010 SP1 之前很久就安装了 STE 模板,我没有这个问题。
检查NeedsHandleCascadeDeleteMethod
in的定义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))
{
如果您看到其他任何内容,您的模板可能以某种方式损坏或您对其进行了修改。尝试再次安装它。