Map to tables when DomainModel still exists

2 posts, 0 answers
  1. Norbert
    Norbert avatar
    35 posts
    Member since:
    Dec 2009

    Posted 03 Oct 2011 Link to this post


    I love your products but I have a question.
    (How) Can I map predefined tables with a predefined domain model? I also want to separate my domain model (business objects) from the data access layer in two different assemblys. Is that possible? When I create a model out of an existing database there is no choice for creating the business objects in a different assembly.

    It would be nice to get some little help,
    thanks in advance
  2. Ivailo
    Ivailo avatar
    318 posts

    Posted 06 Oct 2011 Link to this post

    Hello Norbert,

    If you already have a database and a business objects layer defined, there are two options for you with Telerik OpenAccess ORM:
    1) You can remove the persistence and navigational properties from the existing objects, make them partial and design a Domain Model through reverse-mapping your database. You need to make sure that:
     - the class names are the same as yours - you need to rename the Domain Classes in the Visual Designer where necessary 
     - the code generation of the model is configured to place the auto-generated classes in the same assembly as your existing classes (because of the partial classes linkage). However, you can keep the same namespace structure.
    For more information regarding this separation of business logic and persistence properties in different classes you can refer to the relevant documentation article.

    2) You can take the Code Only approach by using our Fluent Mapping API. This way you define your mapping declaratively in your code, so it will give you the most flexibility. However, have in mind that you will not be able to use the Visual Designer for a visual representation of your model..

    In general I recommend you the second, Code Only approach, despite that it might seem like a lot of coding. It is more straight-forward and it is less likely for you to stumble into difficult mapping situations than while using the less flexible Visual Designer approach.

    As per your second question, the only separation that can currently be achieved with the Visual Designer approach (1) is separating the OpenAccessContext from the generated classes. The Fluent Mapping API (2) would give you more flexibility since its entirely your code that defines the mapping. 

    Do not hesitate to let us know if you need further assistance.

    Kind regards,
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Back to Top