Example #1
0
        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;
        }
Example #2
0
        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);
            }
        }