private bool ExpandKey(EntityKeyInfo key) { if (key.IsExpanded()) { return(true); } if (_keysInExpansion.Contains(key)) { Log.LogError($"Cannot expand key/index {key.GetFullRef()}, ran into key circular reference."); return(false); } try { _keysInExpansion.Add(key); if (key.KeyType.IsSet(KeyType.ForeignKey)) { return(ExpandForeignKey(key)); } ExpandRegularKey(key); } finally { _keysInExpansion.Remove(key); } key.HasIdentityMember = key.ExpandedKeyMembers.Any(m => m.Member.Flags.IsSet(EntityMemberFlags.Identity)); return(true); }
// these are not key names in db, we assign DbKey.Name in DbModelBuilder using some special code public static string ConstructKeyName(this EntityKeyInfo key) { Util.Check(key.IsExpanded(), "KeyMembers list must be expanded, cannot construct name. Entity: {0}, keytype: {1}", key.Entity.Name, key.KeyType); var entity = key.Entity; var tName = entity.TableName ?? entity.Name; var prefix = GetKeyNamePrefix(key.KeyType); if (key.KeyType.IsSet(KeyType.PrimaryKey)) { return(prefix + tName); } else if (key.KeyType.IsSet(KeyType.ForeignKey)) { var target = key.OwnerMember.ReferenceInfo.ToKey.Entity; return(prefix + tName + "_" + (target.TableName ?? target.Name)); } else { var members = key.GetMemberNames(); string memberNames = string.Join(string.Empty, members).Replace("_", string.Empty); //remove underscores in names return(prefix + tName + "_" + memberNames); } }