Ejemplo n.º 1
0
        public DBForeign(string table, ForeignMode mode, Dictionary <string, DBColumn> primaries, PropertyInfo info)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                throw new Exception(string.Format(GeneralMessages.ERR_IS_NULL_OR_EMPTY, "table"));
            }
            if (primaries == null || primaries.Count <= 0)
            {
                throw new Exception(string.Format(GeneralMessages.ERR_IS_NULL, "primaries"));
            }
            if (info == null)
            {
                throw new Exception(string.Format(GeneralMessages.ERR_IS_NULL, "info"));
            }

            this.TableName = table.Trim();
            this.Mode      = mode;
            this.Keys      = primaries;

            this.ValueType = info.PropertyType;
            var types = this.ValueType.GetGenericArguments();

            this.EntityType = (types == null || types.Length <= 0) ? this.ValueType : types[0];

            ForeignType = GetForeignType();
            if (ForeignType == 0)
            {
                throw new Exception(string.Format(GeneralMessages.ERR_FOREIGN_TYPE_INVALID, info.Name, ValueType.FullName));
            }
            if (ForeignType == 2 && !IsFromTableEntity)
            {
                throw new Exception(string.Format(GeneralMessages.ERR_FOREIGN_ENTITY_TYPE_INVALID, info.Name, EntityType.FullName));
            }
        }
Ejemplo n.º 2
0
        public DBForeignAttribute(string table, ForeignMode mode, params string[] externals)
        {
            TableName = (!string.IsNullOrWhiteSpace(table)) ? table.Trim().ToUpper() : string.Empty;
            Mode      = mode;
            Keys      = new List <KeyValuePair <string, string> >();

            if (externals != null && externals.Length > 0)
            {
                foreach (string external in externals)
                {
                    if (string.IsNullOrWhiteSpace(external))
                    {
                        continue;
                    }
                    var raw = external.Trim().ToUpper();
                    if (raw.Contains(saparator))
                    {
                        var columns = raw.Split(new char[] { saparator });
                        var column1 = columns[0].Trim();
                        var column2 = columns[1].Trim();
                        if (string.IsNullOrWhiteSpace(column1) || string.IsNullOrWhiteSpace(column2))
                        {
                            continue;
                        }
                        Keys.Add(new KeyValuePair <string, string>(column1, column2));
                    }
                    else
                    {
                        Keys.Add(new KeyValuePair <string, string>(raw, raw));
                    }
                }
            }
        }