无法生成控制器 [英] Unable To generate a Controller
本文介绍了无法生成控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在数据库中创建代码优先方法但是
我在生成控制器时继续出现此错误
我总是收到此错误消息
无法检索'Identifications.Models.Identification'的元数据。
值不能为空
参数名称: key
这是我的模特到目前为止
I wish to Create A Code First Approach in a Database But
I Keep on Getting This Error When I Generate a Controller
I Always Get This Error Message
Unable To Retrieve Metadata for 'Identifications.Models.Identification'.
Value Cannot be null
Parameter name: key
This is my Model so Far
namespace Identifications.Models
{
public class Identification
{
public Int32 ID { get; set; }
public string FullName { get; set; }
public HttpPostedFileBase file { get; set; }
}
public class DbIdentification : DbContext
{
public DbSet<Identification> Identifications { get; set; }
}
}
这是我的ConnectionString到目前为止
This is my ConnectionString so Far
<connectionstrings>
<add name="DbIdentification">
<connectionString="server=.; database=Sample; Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
</connectionstrings>
希望你能帮我一个大谢谢!
Hope You Can Help me Out Here A Big Thanks!
推荐答案
看到它用于学习示例代码拳头approuch。
http://weblogs.asp.net/scottgu/code-first-development-with-entity-framework-4 [< a href =http://weblogs.asp.net/scottgu/code-first-development-with-entity-framework-4target =_ blanktitle =New Window> ^ ] br />
http://codefirst.codeplex.com/ [ ^ ]
see it for learn with example code fist approuch.
http://weblogs.asp.net/scottgu/code-first-development-with-entity-framework-4[^]
http://codefirst.codeplex.com/[^]
EF需要在每张桌子上PK,所以你需要这个
EF require PK on each table so you need this
namespace Identifications.Models
{
public class Identification
{
[Key]
public Int32 ID { get; set; }
public string FullName { get; set; }
public HttpPostedFileBase file { get; set; }
}
你可以从这里使用更多选项
http://msdn.microsoft.com/en-in/data/jj591583.aspx [ ^ ]
这是代码第一个实体框架,你正在使用,所以Sql需要知道哪个是主键,它将设置。所以需要 [key] 属性。
关注这里 [ ^ ]
以上链接将为您提供代码优先约定。
谢谢
:)
This is code first entity framework, you are using so the Sql needs to know which is the primary key, it is going to set. So [key] attribute is needed.
Follow here[^]
Above link would give you code first conventions.
Thanks
:)
这篇关于无法生成控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文