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

Map to tables when DomainModel still exists

1 Answer 42 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Norbert
Top achievements
Rank 2
Norbert asked on 03 Oct 2011, 09:02 AM
Hello,

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
Norbert

1 Answer, 1 is accepted

Sort by
0
Ivailo
Telerik team
answered on 06 Oct 2011, 07:35 AM
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,
Ivailo
the Telerik team
Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Tags
Data Access Free Edition
Asked by
Norbert
Top achievements
Rank 2
Answers by
Ivailo
Telerik team
Share this question
or