教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 解决Entity Framework4.3实体类提示列名xx无效

解决Entity Framework4.3实体类提示列名xx无效

发布时间:2016-12-02   编辑:jiaochengji.com
教程集为您提供解决Entity Framework4.3实体类提示列名xx无效等资源,欢迎您收藏本站,我们将为您提供最新的解决Entity Framework4.3实体类提示列名xx无效资源
下面我一起来看一个关于解决Entity Framework4.3实体类提示列名xx无效问题办法,如果你碰到此类问题可进入参考一下。

假设有如下一个实体类:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9004')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9004>


public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Remark { get; set; }
}

其中Remark属性另有用途,在数据库中没有对应的字段,这样运行时会出错,提示列名Remark 无效。解决方法是使用NotMapped特性对它进行标记,告诉EF该属性不映射成数据库字段,下边为修改后的实体类:

 

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8773')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8773>public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    [NotMapped]
    public string Remark { get; set; }
}

您可能感兴趣的文章:
解决Entity Framework4.3实体类提示列名xx无效
Jquery 高亮显示文本中重要的关键字
对象池加速游戏内存分配的解决方案
JQuery.Ajax之错误调试帮助信息介绍
jquery post时content-type的几种取值
Java垃圾回收调优教程及实例
PHP Warning: phpinfo() has been disabled函数禁用
seo优化之企业网站标题怎么定位
QueryPHP V1-beta.5 改进 ORM 设计体验
Entity Framework插入数据报错:Validation failed for one or more entities

[关闭]
~ ~