public void AddField(string fieldName, System.Data.DbType fieldType, int length, bool isPrimaryKey, bool requireUnique, FieldOrder searchOrder) { if (this.Registered & !this.AllowRuntimeChanges) { throw new InvalidOperationException("The Entity is already registered, it cannot be modified"); } if (this.Registered & isPrimaryKey) { throw new ArgumentException("The Entity is already registered, you cannot add a primary key", "isPrimaryKey"); } var attr = new FieldAttribute(); attr.FieldName = fieldName; attr.DataType = fieldType; attr.AllowsNulls = !isPrimaryKey; attr.IsPrimaryKey = isPrimaryKey; attr.IsIdentity = EntityAttribute.KeyScheme == KeyScheme.Identity & isPrimaryKey & this.Fields.KeyFields.Count <= 0; attr.Length = length; attr.RequireUniqueValue = requireUnique; attr.SearchOrder = searchOrder; this.Fields.Add(attr); if (this.Registered && EntityDefinitionChanged != null) { EntityDefinitionChanged.Invoke(this, new EntityTypeChangedArgs(this, attr)); } }
public void AddReference(Type referenceType, string referenceField, bool isArray, ReferenceType refType) { if (this.Registered & !this.AllowRuntimeChanges) { throw new InvalidOperationException("The Entity is already registered, it cannot be modified"); } var attr = new ReferenceAttribute(referenceType, referenceField); attr.ReferenceType = ReferenceType.OneToMany; if (refType == ReferenceType.ManyToMany) { attr.ReferenceType = refType; } attr.IsArray = isArray; attr.IsList = !isArray; this.References.Add(attr); if (this.Registered && EntityDefinitionChanged != null) { EntityDefinitionChanged.Invoke(this, new EntityTypeChangedArgs(this, attr)); } }