【发布时间】:2018-03-09 16:56:30
【问题描述】:
我想为模型添加更多验证消息注释(这里的所有模型都是由数据库首先生成的),所以我确实在此链接https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/enhancing-data-validation 的帮助下使用了元数据。未更新模型,但构建失败并显示警告:
错误 6046:无法生成存储函数“fn_diagramobjects”的函数导入返回类型。
错误 CS1061“Account”不包含“ConfirmPassword”的定义,并且找不到接受“Account”类型的第一个参数的扩展方法“ConfirmPassword”(您是否缺少 using 指令或程序集引用?)项目-asp-mvc D:.NET demo\Project\project-asp-mvc\Controllers\UserController.cs 85 活动
这是我从数据库生成的模型:
using System;
using System.Collections.Generic;
public partial class Account
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Account()
{
this.Orders = new HashSet<Order>();
}
public string username { get; set; }
public string password { get; set; }
public Nullable<int> role_id { get; set; }
public virtual Role Role { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Order> Orders { get; set; }
}
Metadata.cs:
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace project_asp_mvc.Models
{
public class AccountMetadata
{
[Required]
[StringLength(50, ErrorMessage = "Username con not be longer than 50")]
[EmailAddress]
public string username { get; set; }
[Required]
[DataType(DataType.Password)]
public string password { get; set; }
[Required]
[NotMapped]
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Please confirm your password again")]
public string ConfirmPassword { get; set; }
}
}
PartialClasses.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace project_asp_mvc.Models
{
[MetadataType(typeof(AccountMetadata))]
public partial class Account
{
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework asp.net-mvc-4