Activityflowcontent is the model class of the solid models
Activityflowcontentmetadata is the model class that he wrote.
The same two class attributes can form a mapping relationship, and additional fields can be added to the activityflowcontent
[Metadatatype (typeof (Activityflowcontentmetadata))]
public partial class Activityflowcontent:ibaseentity
{
[Display (Name = "Activity Flow Classification")]
public string Activityclassificidold {get; set;}
#region Custom Properties
#endregion
}
public class Activityflowcontentmetadata
{
[Scaffoldcolumn (False)]
[Display (Name = "PRIMARY Key", Order = 1)]
public string ID {get; set;}
[Scaffoldcolumn (True)]
[Stringlength (errormessage = "Length not exceeding 36")]
[Display (Name = "Activity class ID", Order = 2)]
Public object Activityclassificid {get; set;}
[Scaffoldcolumn (True)]
[Stringlength (errormessage = "Length not exceeding 200")]
[Display (Name = "Activity Summary", Order = 3)]
Public object Sumary {get; set;}
[Scaffoldcolumn (True)]
[DataType (datatype.multilinetext,errormessage= "character is not formatted correctly")]
[Display (Name = "active Content", Order = 4)]
Public object Content {get; set;}
[Scaffoldcolumn (True)]
[Stringlength (errormessage = "Length not exceeding 50")]
[Display (Name = "keyword", Order = 5)]
Public object Keywords {get; set;}
}
The use of Metadatatype, MVC's model layer data validation
Specifies the metadata class to associate with the data model class
Using System.ComponentModel.DataAnnotations;
Specifies the metadata class to associate with the data model class
[Metadatatype (typeof (Product_metadata))]
public partial class Product
{
Public Product ()
{
This. Productguid = Guid.NewGuid ();
This. Addtime = DateTime.Now;
}
public class Product_metadata
{
Public Guid Productguid {get; set;}
[Required (errormessage = "Product name cannot be empty")]
public string ProductName {get; set;}
Public DateTime addtime {get; set;}
}
}
With this association, you can do some initialization work, and you can do some validation, as well as custom validation error messages, which are equivalent to extending the model entity
Because validation is done in the model layer, so good maintenance, so need to do metadata, and the ADO Entity Data Model associated.
For example, the product price needs to do an input verification, how to do it, please see
[RegularExpression (@ "^ (\d+) (. \d+)?", errormessage = "Price format error")]
[Required (errormessage = "*")]
Public double Productprice {get; set;}
Right, is not very good to expand, later need to modify the validation, as long as the metadata class inside the change can be.
When the controller layer is called, the validation code
if (! Modelstate.isvalid)
{
return View ();
}
The use of Metadatatype, MVC's model layer data validation