Entity Framework学习

原因:自动生成的类中有关联主键,没有自动生成Key及Column

解决方法:在xxx.tt的66行左右修改为

var simpleProperties = typeMapper.GetSimpleProperties(entity);
if (simpleProperties.Any())
{
    var keyIndex = 0; // This is a new line
    foreach (var edmProperty in simpleProperties)
    {
        // The following if block is new
        if (ef.IsKey(edmProperty)) 
        {
#>          [System.ComponentModel.DataAnnotations.Key]
            [System.ComponentModel.DataAnnotations.Schema.Column(Order = <#=keyIndex.ToString()#>)]
<#
            keyIndex++;
#>
<#      }
#>
        <#=codeStringGenerator.Property(edmProperty)#>
<#
    }
}

  

原文地址:https://www.cnblogs.com/punkrocker/p/7653150.html