mardi 27 novembre 2018

Finding relationship columns in an Entity Framework T4 script

I'm trying to create a script to generate tests from an entity framework edmx file. I want to ensure columns are all written and relationships are correct.

I can't compare columns that are database keys since these are automatically generated. The database model also includes references from child records to parents. Any suggestions how to detect columns in the child tables that reference parents? (Columns that participate in relationships).

I've figured out how to iterate over the columns, and to exclude the key column for each table:

    var sqlColumns = typeMapper.GetSimpleProperties(entity);
    if (sqlColumn.Any())
    {
        foreach (var sqlColumnin sqlColumns)
        {
          if ( ! ef.IsKey(sqlColumn) )
          {
#>
                // test for non relationship columns goes here
<#
          }
        }
    }

This version of EF includes the file:

<#@ include file="EF.Utility.CS.ttinclude"#><#@ 

Aucun commentaire:

Enregistrer un commentaire