升级到EF 6.1.1会使[NotMapped]的效果消失 [英] Upgrade to EF 6.1.1 makes effect of [NotMapped] disappear
问题描述
我已经从EF 4.3.1升级到6.1.1,现在看来[NotMapped]注释是无用的.是的,我已经进行了更改以更正汇编,并且在编译时一切看起来都很好.
I have upgraded from EF 4.3.1 to 6.1.1 and now it seems like the annotation [NotMapped] is useless. Yes, i have change to correct assembly and everything looks fine on compilation.
在[NotMapped]出现的所有位置,该属性都作为域属性处理,并且我得到一个错误,即EF无法在数据库中找到匹配的列.
Everywhere where [NotMapped] is present the property is handled as a domain property and i get an error that EF can't find the matching column in database.
示例:
private bool _authenticated = true;
[NotMapped]
public bool Authenticated
{
get { return _authenticated; }
set { _authenticated = value; }
}
是的,看来我可以通过添加...来解决此问题.
Yes, it seems like i can work around this by adding...
modelBuilder.Entity<User>().Ignore(x => x.Authenticated);
...但是,然后,EF6中的[NotMapped]有什么用?
...but then, whats the use of [NotMapped] in EF6?
(升级前工作完美)
推荐答案
通过首先卸载然后在解决方案中的所有项目上重新安装EF来解决.
Solved by first uninstall and then reinstalling EF on all projects in the solution.
我认为,当我第一次升级到EF6时,某些项目在.NET版本中有些不匹配,这使得系统从错误的程序集(.NET而不是EF)中提取了[NotMapped]注释.
I think it was some mismatch in .NET versions for some projects when i upgraded to EF6 the first time which made the system take the [NotMapped] annotaition from the wrong assembly (.NET instead of EF).
这使我想到了它: ...以及大多数行:如果您使用新 .NET 4.5中System.ComponentModel.DataAnnotations.dll程序集的批注 它们不会被代码优先"处理."
...and most the line: "If you use the new annotations from the System.ComponentModel.DataAnnotations.dll assembly in .NET 4.5 they will not be processed by Code First."
这篇关于升级到EF 6.1.1会使[NotMapped]的效果消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!