2013-04-12 115 views
0

林有点困惑。我看到一些代码,在我们使用Linq的一个项目到SQL脚手架或其他框架?

<MetadataType(GetType(Customer.CustomerMeta))> Partial Public Class Customer 
Friend Class CustomerMeta 

    <Required(), StringLength(50)> Public Name As String 
    <Required(), StringLength(50)> Public Address As String 
    <Required(), StringLength(20)> Public EmailAddress As String 
    <StringLength(20)> Public Country As String 
End Class 

,为什么它是这样的创建,但它看起来像一个不同的方法已经从曾经被使用即时消息不是肯定的。

在阅读后,似乎技术可能是脚手架(http://msdn.microsoft.com/en-us/library/cc488469(v=vs.90).aspx),但通过本演练的一半,我意识到许多领域不存在(如global.asax文件)或适用于项目我看到上述代码我可能在这里错误的轨道上。

有谁知道上面正在使用什么技术/框架,如果有我可以参考的文章,以加快速度?如果在这里需要书籍或培训课程,那么我很高兴有人能指引我走向正确的方向。

感谢

+0

Linq To SQL使用代码生成工具。我认为它的T4。 –

回答

0

这些数据验证注释(我不知道确切的“框架”你的情况使用它们,因为它们在.NET框架和编程的人会暴露反对它可以使用它们) :基本上,您可以修饰具有这些属性的成员(ValidationAttributes),然后可以使用此元数据进行一些验证,无论是手动还是某些数据模式规则检查器的自动验证。

在这种情况下,属性Name是: -

  • 必需字段(即,它必须具有在它的东西,并且不为空),
  • 和长度必须
  • 50个字符

等等等等。

后一个约束可能会使前者成为冗余,这取决于分析规则的内容。

+1

['StringLengthAttribute'](http://msdn.microsoft.com/zh-cn/library/system.componentmodel.dataannotations.stringlengthattribute%28v=vs.90%29.aspx)指定了字符串的最大长度,而不是最低限度,使得'Required' *不*冗余。这与谁分析规则无关。 –

+0

@DanielHilgarth [Depends](http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx):_'指定数据中允许的字符的最小和最大长度'即使这样,它也依赖于规则检查器。 –

+1

不使用带有一个参数的构造函数时:http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.stringlengthattribute.aspx。它仅指定最大长度。 –