HELP!!!!!. Questions on Devart Entity Model

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
marcwolf
Posts: 3
Joined: Tue 24 Nov 2009 05:52

HELP!!!!!. Questions on Devart Entity Model

Post by marcwolf » Mon 19 Aug 2013 00:55

Hi Folks. Please forgive any obvious misunderstandings as I am still learning.

I am using the Devart Entity Model to generate my code from Database First, and have a couple of examples working. A while back when I was experimenting with MVC and validation I found that because the code was generated automatically I would loose any field specific validation that I created if using the DataAnnotation method. I found I needed to use partial classes.
http://msdn.microsoft.com/en-us/library ... .100).aspx

With Devart Entity Model I can automatically create the partial classes which makes putting in the validation much easier. But I need to find out where to put this validation i.e. Range(50,100)

Now the questions.... I have created an entity of Sap2kDatEntities with one table being User

Image

DataModel2.User.cs seems to be the partial class that I can put my code that will not be changed on a regeneration.

DataModel2.User.Generated.cs\User and User seems to be linked together.

This is the generated code for the field RoleId

Image

Where would I put my validation so that it will not be overwritten.
This is the DataModel2.User.cs Partial Class that is generated

Image

So to put in a validation of Range(50,100) for RoleId that would not be overwritten I would need to put my code where..

The next question is simpler. After I have the above working and have saved it in a separate project (DLL) so I can reuse it - will the validation still work...

Many thanks for any advice you can offer a beginner who is trying to get a project off the ground. I cannot use Code First as the database is already created and running.

Dave

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: HELP!!!!!. Questions on Devart Entity Model

Post by Shalex » Tue 20 Aug 2013 16:06

There is no need to add Data Annotations attributes manually.

Please open your model, navigate to Tools > Entity Developer > Model Explorer and select your template in the Templates node. Set its Validation Framework property to Data Annotations. Then select a particular class property on a diagram (or in Model Explorer) and initialize the needed attributes from the Validation section in the Properties window. Save the model to regenerate the code.

Does this help?

marcwolf
Posts: 3
Joined: Tue 24 Nov 2009 05:52

Re: HELP!!!!!. Questions on Devart Entity Model

Post by marcwolf » Wed 21 Aug 2013 00:07

Many many thanks for your help I now have the validation working :)

I found this article which also helped re using the validation
http://odetocode.com/blogs/scott/archi ... ions.aspx

Again many thanks
Dave

Post Reply