This is a migrated thread and some comments may be shown as answers.

Data Annotations w/ Model First Mapping?

1 Answer 81 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hunter
Top achievements
Rank 1
Hunter asked on 30 Jul 2013, 04:40 PM
I usually use a code-first approach with Entity Framework 4 and simply put my data annotations in the class above each property. I am sure you can do the same when using the Fluent API. But I am trying to figure out how I would still use data annotations with a Open Access ORM model-first approach since everything is auto-generated from the designer. What file would I put my annotations in?

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 02 Aug 2013, 07:28 AM
Hello Hunter,

Indeed, the workflow you describe seems to be very similar to the one you can use with Telerik OpenAccess ORM.

As an alternative to Visual Designer, OpenAccess ORM offers the Code-Only mapping approach. The quickest and easiest way to combine it with the Model - First one would be to use the Telerik OpenAccess Fluent Library project template and when the Create Model wizard starts to select Empty Model.

Regarding, the DataAnnotation attributes, I would suggest to you to navigate to the Advanced Options dialogue of the Create Model wizard and to select Generate DataAnnotation Attributes. That way, OpenAccess ORM can add to the project a reference to System.ComponentModel.DataAnnotations and once you create your classes you can simply decorate their properties according to your needs.

When you click the Finish button of the wizard, OpenAccess ORM will generate for you a file for the context class and a file for the MetadataSource class only.

From this point on, in this project you can add new classes for the domain entities and to decorate their properties. Once you prepare the metadata in the MetadataSource class and set up the context too, you can persist it in the database with the help of this method.

Please kindly find attached to this message a sample project that shows the place of the attributes.

I hope this helps. If you have additional questions or experience issues, do not hesitate to get back to us.


Regards,
Doroteya
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Tags
Development (API, general questions)
Asked by
Hunter
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or