解决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