开发者

WPF, Entity framefork and validating models

I'm buidling an WPF application using the examples given in the link below as a basis:

http://www.robbagby.com/silverlight/patterns-based-silverlight-development-part-ii-repository-and-validation/

In the example given, the uses the OnValidating partial method to invoke validation and if nessesary, throw an exception when something is not valid.

In the ADO.NET EF, there is no partial method who can allow you to do this, e.g. There is no OnValidating method to override. What there is, are开发者_开发问答 partial methods like: OnPropertyChanging and OnPropertyChanged, but i believe they will be executed immidiatly when you change a property which can given problems when using databinding (i dont have experience with WPF, but as far as i can remember from winforms, a grid for example will immidiatly construct an empty instance of the model and pass in the values afterwards. Therefore throwing an exception at the very beginning because some requirements have not met (is a property set for example).

So based on that, am i just looking in the wrong direction here? is there a better way to perform validation?

Thnx in advance!


You should use ValidationRules in WPF. They are designed just for validation purposes.

Have a look here


You might be interested in the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use validation in WPF + Entity Framework and how to control the Save button when validation errors exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜