实体框架在发布模式下避免使用[NotMapped]属性 [英] Entity Framework avoiding [NotMapped] attribute in release mode
问题描述
我最近将我的项目从4.0升级到了.NET Framework 4.5。完成本
到目前为止,我已经尝试过:
-
从关于类似问题的其他答案中,我尝试删除了引用
System.ComponentModel.DataAnnotations;
在上述文件中-无效 -
尝试复制
.dll
路径中的文件C:\WINDOWS\Microsoft.Net\ assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll **
到应用程序的
bin
目录 -
已更新使用Update-Package安装的
NuGet软件包-重新安装-Project Kyc v4
以上都不适合我,并且如果您想知道-我的 DbContext
错误中提到的模型没有 DbSet
推测是 [NotMapped]
属性由于某种原因被实体框架( 6.1.3
)忽略。我的 System.ComponentModel.DataAnnotations
参考中的版本为 4.0.0.0
,运行时为 v4.0.30319
我们非常感谢您的帮助。谢谢
最后,我发现问题出在 Visual Studio IDE中
本身。由于某种原因,它在执行 Clean / Build或 Rebuild时没有清除旧的引用,因此这些引用发生冲突并与 System.ComponentModel.DataAnnotations.Schema $ c造成混淆$ c>。因此,我手动删除了旧文件并发布到了一个新的空目录。
I have recently upgraded my project to .NET Framework 4.5 from 4.0. After completing all tasks mentioned in this MSDN Migration Guide, I added some changes to the models for supporting Oracle database.
The models are shown here:
namespace KYC_v4.Models
{
[Serializable]
public class Organization
{
public int OrganizationID { get; set; }
[Required]
[Display(Name = "OrganizationName", ResourceType = typeof(Resources.Home))]
[MaxLength(200)]
public string OrganizationName { get; set; }
public virtual List<UserGroup> Groups{get;set;}
public OrganizationDetails Details { get; set; }
public int UserID { get; set; }
[NotMapped]
[MaxLength(100)]
public string membersCount { get; set; }
[NotMapped]
public List<CheckOrgPermissionViewModel> CheckPermission { get; set; }
}
}
public class CheckOrgPermissionViewModel {
public string Permissiontype { get; set; }
public bool isTrue { get; set; }
}
It is running normally when I debug from Visual Studio, but when I try to host it in IIS server, I get this error:
What I have tried so far:
From other answers about similar issues, I tried to remove the reference
System.ComponentModel.DataAnnotations;
in the above files - did not workTried copying the
.dll
file from the pathC:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll**
to the
bin
directory of the applicationUpdated the installed NuGet packages
using Update-Package -reinstall -Project "Kyc v4"
None of the above works for me, and if you are wondering - I do not have the DbSet
for the models mentioned in the error in my DbContext
, so my guess is the [NotMapped]
attribute is being ignored by Entity Framework (6.1.3
) for some reason. The version in my System.ComponentModel.DataAnnotations
reference is 4.0.0.0
and runtime is given as v4.0.30319
Any help is appreciated. Thank you
In the end, I have found out that the issue was with the Visual studio IDE
itself. It was not cleaning the old references while doing "Clean"/"Build" or "Rebuild" for some reason so the references were conflicting and causing confusion with the System.ComponentModel.DataAnnotations.Schema
. So I manually deleted the old files and published to a new empty directory.
这篇关于实体框架在发布模式下避免使用[NotMapped]属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!