在模型期间检测到一个或多个验证错误 [英] One or more validation errors were detected during model

查看:368
本文介绍了在模型期间检测到一个或多个验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命名空间MVCExams.Models

{

[表(adminreg)]

公共类管理员

{

public int recid {get; set;}

public string name {get;组; }

public string userid {get;组; }

public string emailid {get;组; }

public string pswrd {get;组; }

}

}

{在模型生成过程中检测到一个或多个验证错误:\\\\\\\ \\ nMVCExams.Models.admin :: EntityType'admin'没有定义键。定义此EntityType的键。\\\ nnminmins:EntityType:EntitySet'admins'基于没有定义键的'admin'类型。 \ n \\ n}}}



我的尝试:



i尝试更改主键名称然后它也显示相同的

namespace MVCExams.Models
{
[Table("adminreg")]
public class admin
{
public int recid { get; set;}
public string name { get; set; }
public string userid { get; set; }
public string emailid { get; set; }
public string pswrd { get; set; }
}
}
{"One or more validation errors were detected during model generation:\r\n\r\nMVCExams.Models.admin: : EntityType 'admin' has no key defined. Define the key for this EntityType.\r\nadmins: EntityType: EntitySet 'admins' is based on type 'admin' that has no keys defined.\r\n"}

What I have tried:

i tried to change primary key name and all then also it shows same

推荐答案

实体框架使用主键字段在生成的表上创建主键列。



它将列名Id标识为主键。如果recid是主键,请添加[key]属性并尝试。





Entity Framework uses a primary key field to create the primary key column on the generated table.

It identifies column name "Id" as primary key .In your case if recid is the primary key please add [key] attribute and try.


[key]
public int recid { get; set;}





请阅读以下内容。



实体框架代码首次数据注释 [ ^ ]


这篇关于在模型期间检测到一个或多个验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆