是什么,如果我使用的是实体框架(V5.0)数据库中第一种方法使用数据的注释进行验证的最好方法?
这是我通过实体框架创建部分类:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;
namespace ACore
{
using System;
using System.Collections.Generic;
public partial class PayrollMarkup_State
{
[UIHint("StatesEditor")] // <-- I added this line but it will be overwritten
public string State { get; set; }
public Nullable<float> MaintenancePercentage { get; set; }
public Nullable<float> OfficePercentage { get; set; }
}
}
我想这没有成功....
实体框架生成的文件:“PayrollMarkup_State.cs”
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;
namespace ACore
{
using System;
using System.Collections.Generic;
public partial class PayrollMarkup_State
{
public string State { get; set; }
public Nullable<float> MaintenancePercentage { get; set; }
public Nullable<float> OfficePercentage { get; set; }
}
}
然后,我在不同的目录中创建这个文件:“PayrollMarkup_state.cs”
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace ACore.Models
{
[MetadataType(typeof(PayrollMarkupMetadata))]
public partial class PayrollMarkup_State
{
}
public class PayrollMarkupMetadata
{
[UIHint("StatesEditor")]
public string State; // Has to have the same type and name as your model
}
}