开发者

LINQ-to-SQL - C# - OnValidate()

I have a system with 3开发者_如何学C layers and I am using LINQ-to-SQL to persist.

I want to validate if the description field of my object is empty. I am using partial classes and the method OnValidate(). If the field is empty, it throws an exception.

Is this correct?

What do I do after the exception to not close the form, letting the user continue working?

Thank you very much

Sorry for my poor english


How you handle it exactly depends on your what the application is (e.g. ASP.Net, MVC, WebForms), but your exception should return a list of the validation errors so that your view can handle them gracefully, e.g. display them on the form.

There are some good frameworks for handling this, such as XVal if it is a web application.


look into this link which shows bunch of tricks about how to override onValidate() and other linq tricks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜