/// <summary> /// Gets the cached mapped-name of the property. /// </summary> /// <param name="property">The target property.</param> /// <param name="quoted">True whether the string is quoted.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached mapped-name of the property.</returns> public static string Get(PropertyInfo property, bool quoted, IDbSetting dbSetting) { var key = property.DeclaringType.FullName.GetHashCode() + property.Name.GetHashCode() + quoted.GetHashCode(); var result = (string)null; // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out result) == false) { result = PropertyInfoExtension.GetMappedName(property, quoted, dbSetting); m_cache.TryAdd(key, result); } // Return the value return(result); }
///// <summary> ///// Creates a new instance of <see cref="Parameter"/> object. ///// </summary> ///// <param name="name">The name of the parameter.</param> ///// <param name="value">The value of the parameter.</param> //public Parameter(string name, object value) // : this(name, value, false) //{ //} /// <summary> /// Creates a new instance of <see cref="Parameter"/> object. /// </summary> /// <param name="name">The name of the parameter.</param> /// <param name="value">The value of the parameter.</param> /// <param name="prependUnderscore">The value to identify whether the underscope prefix will be prepended.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> internal Parameter(string name, object value, bool prependUnderscore, IDbSetting dbSetting) { // Name is required if (string.IsNullOrEmpty(name)) { throw new NullReferenceException(name); } // Set the properties DbSetting = dbSetting; Name = name.AsAlphaNumeric(true); Value = value; if (prependUnderscore) { PrependAnUnderscore(); } // Set the hashcode m_hashCode = Name.GetHashCode(); if (dbSetting != null) { m_hashCode += dbSetting.GetHashCode(); } }
/// <summary> /// Gets the cached primary property of the data entity. /// </summary> /// <param name="type">The type of the target entity.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached primary property.</returns> public static ClassProperty Get(Type type, IDbSetting dbSetting) { // Variables for the cache var property = (ClassProperty)null; var key = type.FullName.GetHashCode(); // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out property) == false) { // Get all with IsPrimary() flags var properties = PropertyCache.Get(type, dbSetting).Where(p => p.IsPrimary() == true); // Check if there is forced [Primary] attribute property = properties.FirstOrDefault(p => p.GetPrimaryAttribute() != null); // Otherwise, get the first one if (property == null) { property = properties?.FirstOrDefault(); } // Add to the cache (whatever) m_cache.TryAdd(key, property); } // Return the value return(property); }
/// <summary> /// Creates a new instance of <see cref="Field"/> object. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="type">The type of the field.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> public Field(string name, Type type, IDbSetting dbSetting) { // Name is required if (string.IsNullOrEmpty(name)) { throw new NullReferenceException(name); } // Set the name Name = name.AsQuoted(true, true, dbSetting); UnquotedName = name.AsUnquoted(true, dbSetting); // Set the type Type = type; // Set the DbSetting DbSetting = dbSetting; // Set the hashcode m_hashCode = Name.GetHashCode(); if (type != null) { m_hashCode += type.GetHashCode(); } if (dbSetting != null) { m_hashCode += dbSetting.GetHashCode(); } }
/// <summary> /// Creates a new instance of <see cref="DbField"/> object. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="isPrimary">The value that indicates whether the field is primary.</param> /// <param name="isIdentity">The value that indicates whether the field is identity.</param> /// <param name="isNullable">The value that indicates whether the field is nullable.</param> /// <param name="type">The equivalent .NET CLR type of the field.</param> /// <param name="size">The size of the field.</param> /// <param name="precision">The precision of the field.</param> /// <param name="scale">The scale of the field.</param> /// <param name="databaseType">The database type of the field.</param> /// <param name="dbSetting">The database setting to be used.</param> public DbField(string name, bool isPrimary, bool isIdentity, bool isNullable, Type type, int?size, byte?precision, byte?scale, string databaseType, IDbSetting dbSetting) { // Name is required if (string.IsNullOrEmpty(name)) { throw new NullReferenceException("Name"); } // Set the properties Name = name.AsQuoted(true, true, dbSetting); UnquotedName = name.AsUnquoted(true, dbSetting); IsPrimary = isPrimary; IsIdentity = isIdentity; IsNullable = isNullable; Type = type; Size = size; Precision = precision; Scale = scale; DatabaseType = databaseType; DbSetting = dbSetting; // Set the hashcode m_hashCode = name.GetHashCode() + isPrimary.GetHashCode() + isIdentity.GetHashCode() + isNullable.GetHashCode(); if (type != null) { m_hashCode += type.GetHashCode(); } if (size != null) { m_hashCode += size.GetHashCode(); } if (precision != null) { m_hashCode += precision.GetHashCode(); } if (scale != null) { m_hashCode += scale.GetHashCode(); } if (databaseType != null) { m_hashCode += databaseType.GetHashCode(); } if (dbSetting != null) { m_hashCode += dbSetting.GetHashCode(); } }
/// <summary> /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity. /// </summary> /// <param name="type">The type of the target entity.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns> public static IEnumerable <ClassProperty> Get(Type type, IDbSetting dbSetting) { var properties = (IEnumerable <ClassProperty>)null; var key = type.FullName.GetHashCode(); // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out properties) == false) { properties = type.GetProperties().Select(p => new ClassProperty(p, dbSetting)); m_cache.TryAdd(key, properties); } // Return the value return(properties); }
/// <summary> /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity. /// </summary> /// <typeparam name="TEntity">The type of the target entity.</typeparam> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns> public static IEnumerable <ClassProperty> Get <TEntity>(IDbSetting dbSetting) where TEntity : class { var properties = (IEnumerable <ClassProperty>)null; var key = typeof(TEntity).FullName.GetHashCode(); // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out properties) == false) { properties = ClassExpression.GetProperties <TEntity>(dbSetting); m_cache.TryAdd(key, properties); } // Return the value return(properties); }
/// <summary> /// Gets the cached identity property of the data entity. /// </summary> /// <param name="type">The type of the target entity.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached identity property.</returns> public static ClassProperty Get(Type type, IDbSetting dbSetting) { var key = type.FullName.GetHashCode(); var property = (ClassProperty)null; // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out property) == false) { property = PropertyCache.Get(type, dbSetting).FirstOrDefault(p => p.IsIdentity() == true); m_cache.TryAdd(key, property); } // Return the value return(property); }
/// <summary> /// Gets the cached list of <see cref="Field"/> objects of the data entity. /// </summary> /// <param name="type">The type of the target entity.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached list <see cref="Field"/> objects.</returns> public static IEnumerable <Field> Get(Type type, IDbSetting dbSetting) { var key = type.FullName.GetHashCode(); var result = (IEnumerable <Field>)null; // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out result) == false) { result = type.AsFields(dbSetting); m_cache.TryAdd(key, result); } // Return the value return(result); }
/// <summary> /// Gets the cached mapped-name for the entity. /// </summary> /// <param name="type">The type of the target entity.</param> /// <param name="quoted">True whether the string is quoted.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached mapped name of the entity.</returns> internal static string Get(Type type, bool quoted, IDbSetting dbSetting) { var key = type.FullName.GetHashCode() + quoted.GetHashCode(); var result = (string)null; // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out result) == false) { result = DataEntityExtension.GetMappedName(type, quoted, dbSetting); m_cache.TryAdd(key, result); } // Return the value return(result); }
///// <summary> ///// Creates a new instance of <see cref="OrderField"/> object. ///// </summary> ///// <param name="name">The name of the field to be ordered.</param> ///// <param name="order">The ordering direction of the field.</param> //public OrderField(string name, // Order order) // : this(name, order, null) { } /// <summary> /// Creates a new instance of <see cref="OrderField"/> object. /// </summary> /// <param name="name">The name of the field to be ordered.</param> /// <param name="order">The ordering direction of the field.</param> /// <param name="dbSetting">The database setting that is currently in used.</param> public OrderField(string name, Order order, IDbSetting dbSetting) { // Name is required if (string.IsNullOrEmpty(name)) { throw new NullReferenceException(name); } // Set the properties DbSetting = dbSetting; Name = name.AsQuoted(true, dbSetting); UnquotedName = name.AsUnquoted(true, dbSetting); Order = order; // Set the hashcode here m_hashCode = name.GetHashCode() + (int)order; if (dbSetting != null) { m_hashCode += dbSetting.GetHashCode(); } }