LoginSignup
0
0

More than 5 years have passed since last update.

edmxファイルをカスタムツール実行するとFK名が1,2,3となってどれとリレーションしているかわからない問題をジェネレータを改造することで解消

Last updated at Posted at 2015-07-08

多重でリレーションしているテーブルをDBからコードを自動生成すると以下のように変なネーミングになってどのカラムとリレーションしているかわからなくなります(相手のテーブル名順)。

TableA.cs
    using System;
    using System.Collections.Generic;

    public partial class TableA
    {
                        .
                        .
                        .
        public virtual TableB TableB  { get; set; } 
        public virtual TableB TableB1  { get; set; }
        public virtual TableB TableB2  { get; set; }
        public virtual TableB TableB3  { get; set; }
    }

ttファイルを以下のように変えると解消されるよ。

xxbefore.tt
// 50行目くらい 
        this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();

// 200行目くらい
            _code.Escape(navProp),

↓↓↓↓↓↓↓↓↓↓↓

xxafter.tt
// 50行目くらい 
        this.<#=code.Escape(navigationProperty.RelationshipType).Replace("_","")#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();

// 200行目くらい
            _code.Escape(navProp.RelationshipType).Replace("_",""),

ビバ、エドマックス!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0