问题描述
很新的POCO,找到一些谷歌联系,但发现有很多不同的故事。
一些实体框架,延迟加载等连接它的一些纯.det类如是说。
ATLEAST MSDN。
Very new to POCO, find some google links but found many different stories. Some connected with Entity framework, lazy loading etc. Some says its a pure .det class. Atleast MSDN.
有关DEFINE POCO从MSDN LINK:
LINK FOR DEFINE POCO FROM MSDN:msdn.microsoft.com/en-us/library/dd456872.aspx
我相信MSDN(一个简单的认定中),并假定它是一个纯粹的.NET类。
I trust MSDN(a simple defination), and assume that it is a pure .NET Class.
现在就让我来的地步。
如果是带里面只有特性纯.NET类比它是等边在MVC模式。
例子。
Now let me come to the point.IF it is pure .net class with only properties inside it than it is equilateral to "MODEL" in MVC.example.
[Required(ErrorMessage = "Full Name required.")]
[StringLength(20, ErrorMessage = "Username must be under 20 chars.")]
public string UserName { get; set; }
[Required(ErrorMessage = "Email required.")]
[RegularExpression(".+@.+\\..+", ErrorMessage = "Email not valid.")]
public string Email { get; set; }
[Required(ErrorMessage = "PassWord required.")]
[StringLength(20, ErrorMessage = "Maximum 20 chars. allow")]
[DataType(DataType.Password)]
public string Password { get; set; }
高达这个水平很清晰。现在,如果我想要写在MODEL我自己的验证(有条件)
使用
Upto this level it is clear to me. Now if i want to write my own validation (conditional) in MODELusing
ValidationAttribute
或
ValidationAttribute or
IValidatableObject
IValidatableObject
这将不是纯粹的.NET类,如果我没有错。
例如......(类似下面)
this will be not pure .net class if i am not wrong. example.... (Something like below)
public class Wizard : ValidationAttribute,IValidatableObject
{
public override bool IsValid(object value)
{
return base.IsValid(value);
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
throw new NotImplementedException();
}
[Required(ErrorMessage = "Full Name required.")]
[StringLength(20, ErrorMessage = "Username must be under 20 chars.")]
public string UserName { get; set; }
[Required(ErrorMessage = "Email required.")]
[RegularExpression(".+@.+\\..+", ErrorMessage = "Email not valid.")]
public string Email { get; set; }
[Required(ErrorMessage = "PassWord required.")]
[StringLength(20, ErrorMessage = "Maximum 20 chars. allow")]
[DataType(DataType.Password)]
public string Password { get; set; }
}
这是对POCO还?
如果是的话,怎么能包含的方法。(对面MSDN链接)
如果没有,应该在哪里我写下我的验证code(MVC中的当然有条件的验证)。
寻找一个例子一个真正伟大的答案。
推荐答案
波苏斯意味着你不必某些框架中定义的基类,以实现功能继承。基本上,你可以自由地设计自己的类层次结构。
POCOs mean you do not have to inherit from some framework defined base class in order to implement functionality. Basically you are free to design your class hierarchy.
您可以添加自己的方法,无论是验证或一些业务逻辑。
You can add your own methods be it validation or some business logic.
一个反例是从类为实体框架的实体。
A counter example would be to inherit from EntityObject class for entities in Entity Framework.
这篇关于POCO - 如果POCO意味着仅性质,在那里我可以在MVC写验证纯.NET类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!