实体框架工作加载时间问题 [英] Entity frame work load time problem

查看:66
本文介绍了实体框架工作加载时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用MVC 4应用程序并使用Entity Frame工作来连接Sql Server数据库。我在我的Sql db中创建了一个名为vUserRole的View。



我已定义类来从视图中映射数据如下



 public class vUserRole 
{
public int UserId {get;组; }

公共字符串LoginId {get;组; }

公共字符串UserName {get;组; }

public int RoleId {get;组; }

公共字符串RoleName {get;组; }
}





我已在我的DBContext类中定义了如下属性



 public DbSet< vUserRole> vUserRoles {get;组; } 





但是当我运行项目时,我得到以下异常



'pre> {被模型生成期间检测到一个或多个验证错误:\r\\\
\r\\\
\\tSystem.Data.Entity.Edm.EdmEntityType:的EntityTypevUserRole '没有定义的键定义此EntityType.\r\\\
\\tSystem.Data.Entity.Edm.EdmEntitySet的键:EntitySet的:的EntityType‘不具有键vUserRoles’是基于类型‘vUserRole’定义。\\\\ n}





要求为类vUserRole定义密钥。但它代表了一个观点。





请帮助我。



我尝试过:



我需要帮助。在此先感谢

解决方案

您可能需要添加键属性。请试试。



Ex:



 [Key] 
public int UserId {get;组; }


Hi,

I am working in MVC 4 application and using Entity Frame work to connect with Sql Server data base. I have created a View with the name of vUserRole in my Sql db.

I have class defined to map data from the view as follows

public class vUserRole
   {
       public int UserId { get; set; }

       public string LoginId { get; set; }

       public string UserName { get; set; }

       public int RoleId { get; set; }

       public string RoleName { get; set; }
   }



and I have defined the property in my DBContext class as follows

public DbSet<vUserRole> vUserRoles { get; set; }



But when i run the project I get the following exception

{"One or more validation errors were detected during model generation:\r\n\r\n\\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'vUserRole' has no key defined. Define the key for this EntityType.\r\n\\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'vUserRoles' is based on type 'vUserRole' that has no keys defined.\r\n"}



It is asking for a Key to be defined for the class vUserRole. But it is representing a view.


Please, help me.

What I have tried:

I need help. Thanks in advance

解决方案

You may need to add key attribute. Please try.

For Ex:

  [Key]
public int UserId { get; set; }


这篇关于实体框架工作加载时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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