Using Repository Pattern with Entity DataModel

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
inspectorDev
Posts: 19
Joined: Mon 04 Jan 2016 15:04

Using Repository Pattern with Entity DataModel

Post by inspectorDev » Mon 29 Feb 2016 16:58

I am experimenting with the dotConnect Entity Data Model to use with our Oracle db and I want to know if I can:

1. Change the class/properties names so they are not the same as the tables in our Oracle database (which are confusing). The wizard always creates the Data Model classes/properties with the same names as the underlying tables. There doesn't seem to be any way to rename the files under the .edml file.

2. I want to structure the app so my domain objects are separate from the persistence layer, but the wizard puts the dbContext-derived class and domain classes under the .edml file and I am unable to separate them. Basically, this is how my solution should look:

Visual Studio Solution:
Core (parent folder for core abstractions)
-Domain(this folder should contain only the model classes that represent the tables in my db)
Customer.cs
Product.cs
-Repositories (this folder has interfaces for each domain object repo and the generic repo for all obj)
IRepository.cs // for generic domain object functionality. eg, Add() Remove() Get() GetAll().
ICustomerRepository.cs //for object-specific queries. eg, GetTopCustomers()
IProductRepository.cs //for object-specific queries. eg, GetBestSellingProducts()

Persistence (parent folder for database-specific implementations)
MyAppDbContext.cs (dbContext-derived class with DbSets<> of domain objects)
-Repositories (this folder should contain the implementation of my repository interfaces) eg:
Repository.cs //implements the generic repository interface with EF version
CustomerRepository.cs //inherits from the generic repository AND implements the ICustomerRepo
ProductRepository.cs //inherits from the generic repository AND implements the IProductRepo

This solution will reduce query duplication in outer layers. Any ideas on how to achieve this with devart tools?

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

Re: Using Repository Pattern with Entity DataModel

Post by Shalex » Tue 01 Mar 2016 07:03

inspectorDev wrote:1. Change the class/properties names so they are not the same as the tables in our Oracle database (which are confusing). The wizard always creates the Data Model classes/properties with the same names as the underlying tables. There doesn't seem to be any way to rename the files under the .edml file.
You can change the class names in the designer. For this, double click *.edml in Solution Explorer to open it in Entity Developer integrated in Visual Studio, navigate to Tools > Entity Developer > Model Explorer. There are two parts of the model: *Model (represents CSDL) and *Model.Store (represents SSDL). Please rename classes in CSDL, and Entity Developer will preserve an existing mapping to the tables in SSDL. Save the model to regenerate the code.
inspectorDev wrote:2. I want to structure the app so my domain objects are separate from the persistence layer, but the wizard puts the dbContext-derived class and domain classes under the .edml file and I am unable to separate them. Basically, this is how my solution should look: [...]
Open your *.edml, navigate to Model Explorer > Templates. There are two enabled templates DbContext and Repository And Unit of Work, aren't there? The templates have the following properties to set the paths for code generation:
DbContext -> the Context Output and Entities Output properties
Repository And Unit of Work (with "Use DbContext"=True) -> the Data Access Layer Output and Interface Layer Output properties
Set the properties and save the model to regenerate the code. If necessary, remove the previously generated *.cs.

inspectorDev
Posts: 19
Joined: Mon 04 Jan 2016 15:04

Re: Using Repository Pattern with Entity DataModel

Post by inspectorDev » Wed 02 Mar 2016 14:44

Fantastic! Thank you.

Can I move the .edml file location as well?

I really appreciate your responsiveness and valuable feedback.

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

Re: Using Repository Pattern with Entity DataModel

Post by Shalex » Wed 02 Mar 2016 16:35

inspectorDev wrote:Can I move the .edml file location as well?
You can move it like any other file in your project.

Post Reply