Template, determining the navigation property Id

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
billster6809
Posts: 29
Joined: Mon 27 Jan 2014 21:08

Template, determining the navigation property Id

Post by billster6809 » Sun 20 Nov 2016 15:57

To begin with, I would like to place another vote for you to add documentation of the classes available in templates. Since template debugging is not supported, and intellisense doesn't work for me at all in Entity Developer templates (Visual Studio 2015 Enterprise), I have no way to know how to do something without contacting you.

My request. Given the following code:

Code: Select all

       var navProperties = cls.RelationProperties
          .Where(rp => rp.Generate)
          .OfType<EntityRelationProperty>().ToList();

        bool isCollection = navProperty.Multiplicity == Multiplicity.Many;
        if (isCollection) {
           string typeName = navProperty.RelationClass.Name;
           string propertyName = navProperty.Name;
           string keyPropertyInCollectionItemBackToParent = navProperty.???
        }
I want to know how to resolve the part in '???'. In a nav property, how do I get the name of the key property that links the collection item to the collection owner?

For example, if I have an entity A with a collection named B of type C, and I have the model set to add the foreign key properties to C, what property or function do I use in the NavProperty to get the name of that foreign key property, which will be something like AId?

This is a C# Entity Framework 6 POCO model, using dotConnect SQLite

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

Re: Template, determining the navigation property Id

Post by Shalex » Tue 22 Nov 2016 19:47

1. You can use IntelliSense feature in our T4 Editor (completion list appears when you type the '.' character).

This is slightly modified your code:

Code: Select all

  foreach (EntityClass cls in _namespace) {
      var navProperties = cls.RelationProperties
          .Where(rp => rp.Generate)
          .OfType<EntityRelationProperty>().ToList();

      foreach(RelationProperty navProperty in navProperties) {
          bool isCollection = navProperty.Multiplicity == Multiplicity.Many;
          if (isCollection) {
              string typeName = navProperty.RelationClass.Name;
              string propertyName = navProperty.Name;
              string keyPropertyInCollectionItemBackToParent = navProperty.???
          }
      }
  }
Remove ".???", type '.' to get a list of its members. Does it work?

2. Also decompiling C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\EntityDeveloper.Common.dll and C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\EntityDeveloper.Orm.Common.dll may help you to get acquainted with the needed classes and their functionality.

billster6809
Posts: 29
Joined: Mon 27 Jan 2014 21:08

Re: Template, determining the navigation property Id

Post by billster6809 » Tue 06 Dec 2016 20:36

I will use option 2 (decompiling the assemblies) for now.

As for the first question, no, '.' does not work for me and hasn't in a long long time.

Whether I first open the edml file or go directly to the tmpl file, I never get any Intellisense. I verified that opening the template uses "Entity Developer (Default)". I get syntax highlight, but never Intellisense.

Other UI tools I have installed are Resharper and various additions that Developer Express ibraries add.

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

Re: Template, determining the navigation property Id

Post by Shalex » Thu 08 Dec 2016 17:37

1. Try this code. Is that what you need?

Code: Select all

 string keyPropertyInCollectionItemBackToParent = navProperty.OppositeRelationProperty;
2. Does the issue with IntelliSense persist if you uninstall ReSharper?

Post Reply