Tre*_*vor 7 c# dll asp.net-mvc controller visual-studio
我目前正在使用Visual Studio 11 beta进行教程.尝试在我的一个类中设置字段值的最大长度时:
[MaxLength(50)]
public string LastName { get; set; }
Run Code Online (Sandbox Code Playgroud)
它出错并且不会让我编译因为MaxLength()函数存在于两个地方:
错误4类型' System.ComponentModel.DataAnnotations .MaxLengthAttribute'存在于'c:\ Users\me\Documents\Visual Studio 11\ContosoUniversity\packages\EntityFramework.4.1.10331.0\lib \net40\EntityFramework.dll'和' c:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
我试图删除这两个文件,但这只会导致更多问题,因为我的项目中的其他代码依赖于它们.
有没有办法告诉它使用其中一种?
所有这些方法似乎都不适合我..请参阅答案下的评论..还有其他想法吗?
谢谢
在代码顶部使用:
using MaxLength = System.ComponentModel.DataAnnotations
Run Code Online (Sandbox Code Playgroud)
只需从包中卸载EntityFramework并重新安装(EntityFramework).这个对我有用.只需按照下面提到的步骤操作:
1.右键点击参考2.点击管理nugetpackages.
3.单击"卸载"
使用所需的命名空间限定属性
[System.ComponentModel.DataAnnotations.MaxLength(50)]
public string LastName { get; set; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15395 次 |
| 最近记录: |