Data Annotations w/ Model First Mapping?

2 posts, 0 answers
  1. Hunter
    Hunter avatar
    11 posts
    Member since:
    Apr 2013

    Posted 30 Jul 2013 Link to this post

    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?
  2. Doroteya
    Doroteya avatar
    497 posts

    Posted 02 Aug 2013 Link to this post

    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.

    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.
  3. DevCraft banner
Back to Top