【发布时间】:2017-04-26 08:16:25
【问题描述】:
我最近将我的项目从 4.0 升级到 .NET Framework 4.5。在完成MSDN Migration Guide 中提到的所有任务后,我对模型添加了一些更改以支持 Oracle 数据库。
模型如下所示:
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; }
}
当我从 Visual Studio 调试时它运行正常,但是当我尝试将它托管在 IIS 服务器中时,我收到此错误:
到目前为止我所尝试的:
从其他关于类似问题的答案中,我尝试删除上述文件中的引用
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目录 更新了已安装的 NuGet 包
using Update-Package -reinstall -Project "Kyc v4"
以上都不适合我,如果您想知道 - 我的DbContext 中的错误中提到的模型没有DbSet,所以我的猜测是[NotMapped] 属性被忽略出于某种原因,由实体框架 (6.1.3)。我的System.ComponentModel.DataAnnotations 参考中的版本是4.0.0.0,运行时间是v4.0.30319
感谢任何帮助。谢谢
【问题讨论】:
-
使用视图模型(并且您的视图模型应该在一个单独的文件夹中 - 比如
ViewModels,因此它们与 EF 无关) -
如果我这样做,我可以将它与使用 [NotMapped] 的常规模态一起使用而没有任何问题吗?另外,如果是这种情况,为什么在 iisexpress 中调试时我能够毫无问题地运行项目
-
停止在您的视图中使用
[NotMapped]和数据模型并使用视图模型。并且视图模型不包含属于数据模型的属性。 -
不推荐使用 [NotMapped]。如果是,为什么它在我使用它的其他地方没有给我带来问题?
-
据我所知没有。
标签: c# .net asp.net-mvc entity-framework visual-studio-2017