
数据库表TT,EF生成的model是这样的。在这里添加代码,从数据库更新模型是会冲掉。
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码已从模板生成。
//
// 手动更改此文件可能导致应用程序出现意外的行为。
// 如果重新生成代码,将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------ namespace YYMovie.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
public partial class TT
{
public int ID { get; set; }
public string Title { get; set; }
public string Info { get; set; }
public Nullable<System.DateTime> SubmitTime { get; set; }
public Nullable<decimal> Price { get; set; }
}
}
新建一个类 TT 如下,这样就不会被冲掉了
namespace YYMovie.Models
{
/**
* 自定义验证,更新模型时不会被冲掉
*
*/
[MetadataType(typeof(Yanzheng))]
public partial class TT
{
class Yanzheng
{
public int ID { get; set; }
[Display(Name = "标题:")]
[StringLength(, ErrorMessage = "标题太长了")]
public string Title { get; set; }
public string Info { get; set; }
public Nullable<System.DateTime> SubmitTime { get; set; }
public Nullable<decimal> Price { get; set; }
}
}
}