I have an assembly generated using the POCO template using the Entity Framework (for example, "Company.Models.dll"). In addition to the generated POCOs, I also have โsubsequentโ partial classes that define metadata using System.ComponentModel.DataAnnotations. So, for example, Company.Models.Customer is auto-generated (in a separate folder), and then I have a partial class with the same namespace. Inside this partial class, I define an inner class for metadata ... For example:
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace Company.Models
{
[MetadataType(typeof (CustomerMetaData))]
public partial class Customer
{
public override string ToString()
{
return String.Format("Id: {0}, Name: {1}", Id, Name);
}
public class CustomerMetaData
{
[ScaffoldColumn(false)]
public int Id { get; set; }
[DisplayName("Name")]
[Required(ErrorMessage = "Customer Name is required.")]
[StringLength(100, ErrorMessage = "Customer name cannot exceed 100 characters.", MinimumLength = 2)]
public string Name { get; set; }
}
}
}
, , , MVC MVC (, Bind). Company.Models.dll System.Web.Mvc.dll.
, , ?
...
1
: POCO MVC "" , ViewModels ( , AutoMapper ) POCOs MVC. ViewModels POCOs. , ...
2
Bind (. http://www.asp.net/mvc ). :
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Customer customerToCreate)
{
if (!ModelState.IsValid)
return View();
return RedirectToAction("Index");
}
System.Web.Mvc dll POCO Bind .
, ASP.NET MVC, ...
, ?;)