internal SchemaItem GetFieldInfoByPropertyName(string propertyName) { SchemaItem fieldInfo = null; SchemaItems.TryGetValue(propertyName, out fieldInfo); return(fieldInfo); }
internal virtual void Init(Type objectType, IDBAccess dbAccess) { TypeSchema entityInfo = ORMSchemaCache.GetTypeSchema(objectType); SchemaItem fieldInfo = entityInfo.GetFieldInfoByPropertyName(this._propertyName); if (fieldInfo == null) { throw new ArgumentException(string.Format("{0} - Property \"{1}\" not define a mapping field.", this.GetType(), _propertyName)); } Type type = fieldInfo.ProInfo.PropertyType; type = Nullable.GetUnderlyingType(type) ?? type; this._dbType = ORMHelper.GetDbTypeByName(type); this._fieldName = fieldInfo.MappingFieldAttribute.FieldName; this._dbAccess = dbAccess; }
private void InitSchemaItems(Type entityType) { if (this.SchemaItems == null) { SchemaItems = new Dictionary <string, SchemaItem>(); } PropertyInfo[] propertyInfos = entityType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (PropertyInfo pro in propertyInfos) { SchemaItem temp = this.FieldInfo(pro); if (temp != null) { SchemaItems.Add(pro.Name, temp); } } }
private string ToOrderByClause(Type entityType, params SortInfo[] orderBy) { TypeSchema entityInfo = ORMSchemaCache.GetTypeSchema(entityType); string orderByStr = ""; if (null != orderBy && orderBy.Length > 0) { foreach (SortInfo tempSortInfo in orderBy) { SchemaItem fieldInfo = entityInfo.GetFieldInfoByPropertyName(tempSortInfo.PropertyName); if (fieldInfo == null) { throw new ArgumentException("Sort property not define a mapping field. - \"" + tempSortInfo.PropertyName + "\""); } string tempName = GetQuotedName(fieldInfo.MappingFieldAttribute.FieldName); if (tempSortInfo.Direction == SortDirection.Desc) { orderByStr += "," + tempName + " Desc"; } else { orderByStr += "," + tempName; } } if (orderByStr.Length > 0) { orderByStr = orderByStr.Substring(1); //remove the first char ','. } return(string.Format(" ORDER BY {0}", orderByStr)); } else { return(orderByStr); } }