开发者

Entities field length constraint

I'm currently working with Entities (using visual studio 2008, FW 3.5 SP1). I created my entities from the database, and everything is ok, except that my length constraints on the string fields are not enforced. Browsing the internet, I found out that this is quite normal (see this blog post),开发者_运维知识库 and that Entities sends the data without check to the database, to possibly send exceptions.

I know I could write partial classes for my entities, and use the On<Fieldname>Changing methods, but this would require quite an amount of repetitive code to be written. Moreover if I change a length in the DB, this would require me to change my code as well.

So my question is: Is there a generic way to to this ? Is it possible, for each data type which has a maximum length to check if the provided value is fitting ?


As I didn't find a way to do this in a generic way, I finally wrote all On<Fieldname>Changing methods, and made a small generic verification framework, which throws exceptions when some criteria is not met.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜