原因:自动生成的类中有关联主键,没有自动生成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)#>
<#
}
}

  

Entity Framework学习 - 5.DB First执行时提示model没有key的更多相关文章

  1. Entity Framework 学习笔记(二)之数据模型 Model 使用过程

    Entity Framework  数据模型 Model 创建的使用: 开发环境:VS2012 数据库:SQL Server 2008 Entity Framework  版本:6.12 下面是新建的 ...

  2. Entity Framework 学习中级篇1—EF支持复杂类型的实现

    本节,将介绍如何手动构造复杂类型(ComplexType)以及复杂类型的简单操作. 通常,复杂类型是指那些由几个简单的类型组合而成的类型.比如:一张Customer表,其中有FristName和Las ...

  3. Entity Framework 学习

    Entity Framework 学习初级篇1--EF基本概况 Entity Framework 学习初级篇2--ObjectContext.ObjectQuery.ObjectStateEntry. ...

  4. MVC5 Entity Framework学习之实现主要的CRUD功能

    在上一篇文章中,我们使用Entity Framework 和SQL Server LocalDB创建了一个MVC应用程序,并使用它来存储和显示数据.在这篇文章中,你将对由 MVC框架自己主动创建的CR ...

  5. Entity Framework 学习整理(分播客整理)

    MSDN: http://msdn.microsoft.com/en-us/data/aa937723 台湾博客: http://www.dotblogs.com.tw/yc421206/ http: ...

  6. Entity Framework学习笔记

    原文地址:http://www.cnblogs.com/frankofgdc/p/3600090.html Entity Framework学习笔记——错误汇总   之前的小项目做完了,到了总结经验和 ...

  7. Entity Framework 学习整理

    MSDN: http://msdn.microsoft.com/en-us/data/aa937723 台湾博客: http://www.dotblogs.com.tw/yc421206/ http: ...

  8. Entity Framework 学习笔记(2)

    上期回顾:Entity Framework 学习笔记(1) Entity Framework最主要的东西,就是自己创建的.继承于DbContext的类: /// <summary> /// ...

  9. Entity Framework学习初级篇2

    Entity Framework 学习初级篇2--ObjectContext.ObjectQuery.ObjectStateEntry.ObjectStateManager类的介绍 本节,简单的介绍E ...

随机推荐

  1. DapperExtensions and Dapper.Contrib在表构架不是默认dbo时的处理 DapperExtensions and Dapper.Contrib with non-dbo Schema

    什么是数据库的Schema dbo是一个构架(schema),与sql2000不同的是,在sql2005中,表的调用格式如下:"数据库名.构架名.表名",同一个用户可以被授权访问多 ...

  2. springmvc上传,下载

    参考: 上传: 如下代码,可将上传内容复制到上传地址 file.transferTo(new File(realPath + File.separator + realName)); http://b ...

  3. WPS 2019 多个sheet表拆分成独立的excel文件

    参考: https://www.cnblogs.com/hackxiyu/p/8945975.html 场景:将多个sheet表拆分成独立的excel文件 一.安装VB工具: 默认情况下:wps -- ...

  4. twisted 学习笔记一:事件循环

    from twisted.internet import reactor import time def printTime(): print "Current time is", ...

  5. 10.8Xadmin url注册

    2018-10-8 16:45:31 这两天在弄我的服务器,就是是看各种教程 死活部署不好我的Django项目 博客网站 过几天再弄! 越努力,越幸运!永远不要高估自己! 通过两个方法,通过类变量找到 ...

  6. 利用profiler工具提高NC-Verilog仿真效率

    大家进行芯片验证时,一般都会遇到仿真速度很慢.效率不高的问题.目前发现了一个方法可以debug上述问题.即,利用NC的profiler工具. 关于profiler工具,我把文档<Cadence® ...

  7. easyui combobox setValue方法不能触发onSelect事件

    //setValue方法不能触发onSelect事件 //$("#FundingSource").combobox("setValue", data.Fundi ...

  8. {python之IO多路复用} IO模型介绍 阻塞IO(blocking IO) 非阻塞IO(non-blocking IO) 多路复用IO(IO multiplexing) 异步IO(Asynchronous I/O) IO模型比较分析 selectors模块

    python之IO多路复用 阅读目录 一 IO模型介绍 二 阻塞IO(blocking IO) 三 非阻塞IO(non-blocking IO) 四 多路复用IO(IO multiplexing) 五 ...

  9. keil 生成 bin文件

    D:\Keil_v5\ARM\ARMCC\bin\fromelf.exe --bin -o  $L@L.bin #L 这个就是keil的默认安装路径

  10. POJ 1816 - Wild Words - [字典树+DFS]

    题目链接: http://poj.org/problem?id=1816 http://bailian.openjudge.cn/practice/1816?lang=en_US Time Limit ...