Example #1
0
        public virtual string ForeignKeyConstraintSyntax(PropertyInfo propertyInfo)
        {
            Attributes.ForeignKeyAttribute fk = propertyInfo.GetForeignKeyAttribute();
            string cascadeDelete = (fk?.CascadeDelete ?? false) ? " ON DELETE CASCADE" : string.Empty;
            string firstLine     = $"CONSTRAINT {ApplyDelimiter(propertyInfo.ForeignKeyName(this))} FOREIGN KEY (\r\n";

            EnumTableAttribute enumTable;

            if (propertyInfo.IsEnumForeignKey(out enumTable))
            {
                return
                    (firstLine +
                     $"\t{ApplyDelimiter(propertyInfo.SqlColumnName())}\r\n" +
                     $") REFERENCES {ApplyDelimiter(enumTable.FullTableName())} (\r\n" +
                     $"\t{ApplyDelimiter("Value")}\r\n" +
                     ")");
            }
            else
            {
                return
                    (firstLine +
                     $"\t{ApplyDelimiter(propertyInfo.SqlColumnName())}\r\n" +
                     $") REFERENCES {GetTableName(fk.PrimaryTableType)} (\r\n" +
                     $"\t{ApplyDelimiter(fk.PrimaryTableType.IdentityColumnName())}\r\n" +
                     ")" + cascadeDelete);
            }
        }
Example #2
0
 public bool IsReferencedBy(PropertyInfo propertyInfo)
 {
     Attributes.ForeignKeyAttribute fk = propertyInfo.GetAttribute <Attributes.ForeignKeyAttribute>();
     if (fk != null)
     {
         return(fk.PrimaryTableType.Equals(_modelType));
     }
     return(false);
 }