我最近将项目从4.0升级到.NET Framework 4.5。完成此MSDN Migration Guide中提到的所有任务后,我在模型中添加了一些用于支持Oracle数据库的更改。在发布模式下避免[NotMapped]属性的实体框架
的模型如下所示:
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;
- 没有工作试图从路径
C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll**
复制
.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中调试 – insomniac
停止在视图中使用'[NotMapped]'和数据模型并使用视图模型。视图模型不包含属于数据模型的属性。 –