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

Disabling navigation properties

1 Answer 45 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.
Andrew
Top achievements
Rank 1
Andrew asked on 02 May 2013, 03:10 PM
I am using a repository pattern in a database-first environment in my data layer, and want to route all queries through that. Therefore I'd like to disable navigation properties from being generated on my model classes. Currently I'm just editing the association through the designer and unchecking the box for the navigation property, but I'm looking for a more automated way of doing this when the classes are generated (so when a new table is added this step doesn't have to be done).

I figure I can customize the T4 templates, but what would I check to determine if the property being rendered is a navigation property or not?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Yordan
Telerik team
answered on 06 May 2013, 03:20 PM
Hi Andrew,

The desired functionality could be achieved by modifying the template located in (OpenAccess ORM Install Folder)\dsl(Version of Visual Studio)\CodeGenerationTemplates\CSharp\Includes\Specific.ttinclude. The subfolder if Visual Studio 2012 is used will be dsl2012 and dsl2010 if Visual Studio 2010 is used. The generation of navigational properties will be skipped if the following code is inserted at line 219 of the aforementioned file:
 
if (propertyType.StartsWith("IList") || this.DomainModel.Bridge.MetaModel.PersistentTypes.Any(p => p.Name == propertyType))
    {
        return;
    }

After the model is regenerated with this code template no navigational properties in the generated classes will be available. For example, a category class will not have collection of products and product type will not have a property that will reference the category type.

When modifying code templates it is good approach to follow best practices described in this article.

Please find the attached file as a modified version of Specific.ttinclude so the generated code using this template wont have navigational properties.

If there are any difficulties using the modified template or if the achieved behavior is not suitable in your scenario do not hesitate to contact us again.

All the best,
Yordan
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Tags
Development (API, general questions)
Asked by
Andrew
Top achievements
Rank 1
Answers by
Yordan
Telerik team
Share this question
or