Silverlight 3 架构和实现 DataAnnotations - Adivce
我正在使用 Silverlight 3 和 ADO.NET 数据服务,并使用自定义构建的模型(单独的项目)和 DAL(单独的项目))。在我的 Silverlight 项目中,我创建了一个引用我的 .svc 文件的 [服务引用],该文件又指向我的模型。
这是我的问题:我想使用 DataAnnotations (System.ComponentModel.DataAnnotations) 的丰富功能,但是我到底将这些属性放在哪里?如果我用这些注释按模型进行装饰,我不会看到它们在我的 [服务参考] 生成的代理代码中呈现。我只看到我的类及其成员,但没有 DataAnnotations (Reference.cs)。
我知道如果我手动更改 (Reference.cs) 文件并添加一些 DataAnnotations,这些更改会渗透到我的 Silverlight 客户端。我不认为我应该更新生成的代码,即代理代码(Reference.cs)。所以,我的问题是,在我的独立项目(Web、SL、模型、DAL)的 Visual Studio 结构中,我是否可以抛出/扩展此自定义数据源(模型)以利用 DataAnnotations?
我想要这样的东西:
[Required]
public string FirstName
{
get
{
return this._FirstName;
}
set
{
this.OnFirstNameChanging(value);
this._FirstName = value;
this.OnFirstNameChanged();
}
}
I am uisng Silverlight 3 and ADO.NET Data Services with a cusotm-built Model (separate project) and DAL (separate project)) in place. Within my Silverlight project, I create a [Service Reference] that references my .svc file that in turn points to my Model.
Here's my question: I would like to use the rich features of DataAnnotations (System.ComponentModel.DataAnnotations) but where exactly do I put these attributes? If I decorate by Model with these annotations, I don't see them rendered in my [Service Reference]-generated proxy code. I just see my classes with its members, but no DataAnnotations (Reference.cs).
I know if I manually change the (Reference.cs) file and add some DataAnnotations, these changes to trickle throught to my Silverlight Client. I don't believe I should be updating generated code, i.e. proxy code w/in (Reference.cs). So, my question is, where in my Visual Studio structure of separated projects (Web, SL, Model, DAL), do I throw/extend this custom datasource (Model) to utilize DataAnnotations?
I would like something like this:
[Required]
public string FirstName
{
get
{
return this._FirstName;
}
set
{
this.OnFirstNameChanging(value);
this._FirstName = value;
this.OnFirstNameChanged();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个替换代码生成器,用于生成 ADO.NET 数据服务代理类并在我的 Niagara 项目中自动添加验证:
http: //niagara.codeplex.com
I have a replacement code gen for producing ADO.NET Data Service proxy classes and adding in the validation automatically in my Niagara Project:
http://niagara.codeplex.com
我认为查看这篇文章可能会让您了解肖恩发表评论的原因。你的问题的简短答案是。遵循 ModelView-View-Model (MVVM),silverlight 开发风格,然后将 DataAnnotations 放在模型中的属性上,这是一个很大的主题,您需要首先阅读和理解它。我建议您查看 RIA 服务(我认为它现在称为 WCF 服务),如果您想将验证逻辑从 WCF 服务传播回客户端,它将对您有很大帮助。
I think checking this article out might give you some insight as to why Shawn posted his comment. The short answer to your question is. Follow the ModelView-View-Model (MVVM), style of silverlight development, then place DataAnnotations on the properties in your Model, its a huge topic and you need to read and understand it first. I suggest you check out RIA services,(i think its know as WCF services now), that will help you out alot if you want to propagate Validation logic from the WCF service, back to the client.