public ColumnModification( [NotNull] IUpdateEntry entry, [NotNull] IProperty property, [NotNull] IRelationalPropertyAnnotations propertyAnnotations, [NotNull] Func <string> generateParameterName, bool isRead, bool isWrite, bool isKey, bool isCondition, bool isConcurrencyToken) { Check.NotNull(entry, nameof(entry)); Check.NotNull(property, nameof(property)); Check.NotNull(propertyAnnotations, nameof(propertyAnnotations)); Check.NotNull(generateParameterName, nameof(generateParameterName)); Entry = entry; Property = property; ColumnName = propertyAnnotations.ColumnName; _generateParameterName = generateParameterName; IsRead = isRead; IsWrite = isWrite; IsKey = isKey; IsCondition = isCondition; IsConcurrencyToken = isConcurrencyToken; }
/// <summary> /// Creates a new <see cref="ColumnModification" /> instance. /// </summary> /// <param name="entry"> The <see cref="IUpdateEntry" /> that represents the entity that is being modified. </param> /// <param name="property"> The property that maps to the column. </param> /// <param name="propertyAnnotations"> Provides access to relational-specific annotations for the column. </param> /// <param name="generateParameterName"> A delegate for generating parameter names for the update SQL. </param> /// <param name="isRead"> Indicates whether or not a value must be read from the database for the column. </param> /// <param name="isWrite"> Indicates whether or not a value must be written to the database for the column. </param> /// <param name="isKey"> Indicates whether or not the column part of a primary or alternate key.</param> /// <param name="isCondition"> Indicates whether or not the column is used in the <c>WHERE</c> clause when updating. </param> /// <param name="isConcurrencyToken"> Indicates whether or not the column is acting as an optimistic concurrency token. </param> public ColumnModification( [NotNull] IUpdateEntry entry, [NotNull] IProperty property, [NotNull] IRelationalPropertyAnnotations propertyAnnotations, [NotNull] Func <string> generateParameterName, bool isRead, bool isWrite, bool isKey, bool isCondition, bool isConcurrencyToken) : this( Check.NotNull(propertyAnnotations, nameof(propertyAnnotations)).ColumnName, originalValue : null, value : null, property : property, isRead : isRead, isWrite : isWrite, isKey : isKey, isCondition : isCondition) { Check.NotNull(entry, nameof(entry)); Check.NotNull(property, nameof(property)); Check.NotNull(generateParameterName, nameof(generateParameterName)); Entry = entry; IsConcurrencyToken = isConcurrencyToken; _generateParameterName = generateParameterName; _useParameters = true; }
public ColumnModification( [NotNull] IUpdateEntry entry, [NotNull] IProperty property, [NotNull] IRelationalPropertyAnnotations propertyAnnotations, [NotNull] ParameterNameGenerator parameterNameGenerator, bool isRead, bool isWrite, bool isKey, bool isCondition) { Check.NotNull(entry, nameof(entry)); Check.NotNull(property, nameof(property)); Check.NotNull(propertyAnnotations, nameof(propertyAnnotations)); Check.NotNull(parameterNameGenerator, nameof(parameterNameGenerator)); Entry = entry; Property = property; ColumnName = propertyAnnotations.ColumnName; _parameterName = isWrite ? new LazyRef <string>(parameterNameGenerator.GenerateNext) : new LazyRef <string>((string)null); _originalParameterName = isCondition ? new LazyRef <string>(parameterNameGenerator.GenerateNext) : new LazyRef <string>((string)null); _outputParameterName = isRead ? new LazyRef <string>(parameterNameGenerator.GenerateNext) : new LazyRef <string>((string)null); IsRead = isRead; IsWrite = isWrite; IsKey = isKey; IsCondition = isCondition; }
/// <summary> /// Oracle值生成策略 /// </summary> /// <param name="fallbackToModel">回退模式</param> /// <returns></returns> public virtual OracleValueGenerationStrategy?GetOracleValueGenerationStrategy(bool fallbackToModel) { OracleValueGenerationStrategy?result = (OracleValueGenerationStrategy?)Annotations.Metadata[OracleAnnotationNames.ValueGenerationStrategy]; if (result.HasValue) { return(result); } IRelationalPropertyAnnotations relationalPropertyAnnotations = Property.Relational(); if (!fallbackToModel || Property.ValueGenerated != ValueGenerated.OnAdd || relationalPropertyAnnotations.DefaultValue != null || relationalPropertyAnnotations.DefaultValueSql != null || relationalPropertyAnnotations.ComputedColumnSql != null) { return(null); } OracleValueGenerationStrategy?valueGenerationStrategy = Property.DeclaringEntityType.Model.Oracle().ValueGenerationStrategy; if (valueGenerationStrategy == OracleValueGenerationStrategy.SequenceHiLo && IsCompatibleSequenceHiLo(Property)) { return(OracleValueGenerationStrategy.SequenceHiLo); } if (valueGenerationStrategy == OracleValueGenerationStrategy.IdentityColumn && IsCompatibleIdentityColumn(Property)) { return(OracleValueGenerationStrategy.IdentityColumn); } return(null); }
public override TableMetaInfo GetTableMetaInfo(Type type) { IModel model = db.Model; IEntityType entityType = model.FindEntityType(type); IEntityType[] allEntityTypes = model.GetEntityTypes().ToArray(); IProperty[] entityProperties = entityType.GetProperties().ToArray(); IRelationalEntityTypeAnnotations mapping = entityType.Relational(); EFPropertyInfo[] pProperties = new EFPropertyInfo[entityProperties.Length]; // Column info for (int i = 0; i < entityProperties.Length; i++) // (var property in entityProperties) { { IProperty prop = entityProperties[i]; IRelationalPropertyAnnotations rProp = prop.Relational(); if (rProp == null || rProp.ColumnName.IsNulle()) { continue; } bool isIndex = prop.IsIndex(); var idx1 = prop.GetContainingKeys().ToArray(); EFPropertyInfo pInfo = new EFPropertyInfo() { EntityName = prop.Name, ColumnName = rProp.ColumnName, IsIdentity = false, IsKey = prop.IsKey(), IsIndex = isIndex, IsPrimaryKey = prop.IsPrimaryKey() }; string columnType = rProp.ColumnType; pProperties[i] = pInfo; } ; var info = new TableMetaInfo() { TableName = mapping.TableName, //table.Table, // watch out! not table.Name TableSchema = mapping.Schema, //table.Schema, TypeNameFull = entityType.Name, // or: == type.FullName, TypeName = type.Name, TableColumnNames = pProperties.Select(p => p.ColumnName).Where(n => n.NotNulle()).ToArray(), //declaredProps.Select(dp => dp.Name).ToArray(), EntityPropertyNames = pProperties.Select(p => p.EntityName).Where(n => n.NotNulle()).ToArray(), //mapped.Select(dd => dd.Name).ToArray() KeyColumnNames = pProperties.Where(p => p != null && p.IsKey).Select(p => p.ColumnName).ToArray(), // table.ElementType.KeyMembers.Select(m => m.Name).ToArray(), }; return(info); }
public IEnumerable <ColumnMapping <TEntity> > GetColumns() { foreach (IProperty property in _entityType.GetProperties()) { IRelationalPropertyAnnotations relationalProperty = property.Relational(); bool isKey = _entityType.FindPrimaryKey().Properties.Contains(property); _relationSqlTypeTranslator.GetMetaData(relationalProperty.ColumnType, out int?precision, out int?scale, out System.Data.DbType dbType); yield return(new ColumnMapping <TEntity>( dbColumnName: relationalProperty.ColumnName, dbType: dbType, isIdentity: property.ValueGenerated == ValueGenerated.OnAdd, propertyInfo: typeof(TEntity).GetProperty(property.Name), precision: precision, isRequired: !property.IsNullable, length: property.GetMaxLength(), scale: scale )); } }
public static DatabaseColumn GetColumn(this DatabaseModel model, IRelationalEntityTypeAnnotations table, IRelationalPropertyAnnotations column) { return(GetColumn(model, table.Schema, table.TableName, column.ColumnName)); }
public static bool ColumnExists(this DatabaseModel model, IRelationalEntityTypeAnnotations table, IRelationalPropertyAnnotations column) { return(ColumnExists(model, table.Schema, table.TableName, column.ColumnName)); }