/// ------------------------------------------------------------------------------------ public void PostDeserializeInitialization(PaProject project) { if (Type == DataSourceType.SA && FieldMappings.Count == 0) { // Make sure SA data sources have mappings. This check should really only be // necessary when upgrading from a project last saved in version 3.0.1 of PA. FieldMappings = CreateDefaultSaMappings(project.Fields).ToList(); } else if (Type == DataSourceType.FW) { // Make sure FW6 data source mappings include all the default FW6 fields // that cannot be mapped in the data source properties dialog box. This // check should only be necessary the first time the project has been // opened after having been migrated to version 3.3.0 foreach (var fname in Properties.Settings.Default.AllPossibleFw6Fields) { if (!Properties.Settings.Default.Fw6FieldsMappableInPropsDlg.Contains(fname) && !FieldMappings.Any(m => m.PaFieldName == fname)) { FieldMappings.Add(new FieldMapping( project.Fields.Single(f => f.Name == fname), false)); } } } }
public override void PopulateMappings() { FieldMappings.Add(FieldType.Binary, new FieldMapInfo("nvarchar({0})", "200")); FieldMappings.Add(FieldType.Bool, new FieldMapInfo("bit")); FieldMappings.Add(FieldType.Char, new FieldMapInfo("nvarchar({0})", "1")); FieldMappings.Add(FieldType.UnicodeChar, new FieldMapInfo("nvarchar({0})", "1")); FieldMappings.Add(FieldType.Date, new FieldMapInfo("DATETIME")); FieldMappings.Add(FieldType.Int, new FieldMapInfo("int")); FieldMappings.Add(FieldType.Long, new FieldMapInfo("bigint")); FieldMappings.Add(FieldType.Real, new FieldMapInfo("real")); FieldMappings.Add(FieldType.Money, new FieldMapInfo("Money")); FieldMappings.Add(FieldType.String, new FieldMapInfo("NVARCHAR({0})", "200")); FieldMappings.Add(FieldType.Default, new FieldMapInfo("NVARCHAR({0})", "200")); FieldMappings.Add(FieldType.Time, new FieldMapInfo("NVARCHAR(20)")); FieldMappings.Add(FieldType.UnicodeString, new FieldMapInfo("NVARCHAR({0})", "200")); FieldMappings.Add(FieldType.Text, new FieldMapInfo("ntext")); FieldMappings.Add(FieldType.UnicodeText, new FieldMapInfo("ntext")); }
public override void PopulateMappings() { FieldMappings.Add(FieldType.Binary, new FieldMapInfo("BLOB")); FieldMappings.Add(FieldType.Bool, new FieldMapInfo("BOOL")); FieldMappings.Add(FieldType.Char, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.UnicodeChar, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.Date, new FieldMapInfo("DATETIME")); FieldMappings.Add(FieldType.Int, new FieldMapInfo("INTEGER")); FieldMappings.Add(FieldType.Long, new FieldMapInfo("INTEGER")); FieldMappings.Add(FieldType.Real, new FieldMapInfo("DOUBLE")); FieldMappings.Add(FieldType.Money, new FieldMapInfo("DECIMAL")); FieldMappings.Add(FieldType.String, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.Time, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.UnicodeString, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.Text, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.UnicodeText, new FieldMapInfo("VARCHAR")); FieldMappings.Add(FieldType.Default, new FieldMapInfo("VARCHAR")); }
public override void PopulateMappings() { FieldMappings.Add(FieldType.Binary, new FieldMapInfo("LONGBLOB")); FieldMappings.Add(FieldType.Bool, new FieldMapInfo("TINYINT({0})", "1")); FieldMappings.Add(FieldType.Char, new FieldMapInfo("VARCHAR({0})", "1")); FieldMappings.Add(FieldType.UnicodeChar, new FieldMapInfo("VARCHAR({0}) CHARSET utf8", "1")); FieldMappings.Add(FieldType.Date, new FieldMapInfo("DATETIME")); FieldMappings.Add(FieldType.Int, new FieldMapInfo("INT({0})", "11")); FieldMappings.Add(FieldType.Long, new FieldMapInfo("BIGINT({0})", "20")); FieldMappings.Add(FieldType.Real, new FieldMapInfo("DOUBLE")); FieldMappings.Add(FieldType.String, new FieldMapInfo("VARCHAR({0})", "200")); FieldMappings.Add(FieldType.Money, new FieldMapInfo("NUMERIC")); FieldMappings.Add(FieldType.Default, new FieldMapInfo("VARCHAR({0})", "200")); FieldMappings.Add(FieldType.Time, new FieldMapInfo("TIME")); FieldMappings.Add(FieldType.UnicodeString, new FieldMapInfo("VARCHAR({0}) CHARSET utf8", "200")); FieldMappings.Add(FieldType.Text, new FieldMapInfo("LONGTEXT")); FieldMappings.Add(FieldType.UnicodeText, new FieldMapInfo("LONGTEXT CHARSET utf8")); }
public override void PopulateMappings() { FieldMappings.Add(FieldType.Binary, new FieldMapInfo("bytea[]")); FieldMappings.Add(FieldType.Bool, new FieldMapInfo("boolean")); FieldMappings.Add(FieldType.Char, new FieldMapInfo("character")); FieldMappings.Add(FieldType.UnicodeChar, new FieldMapInfo("character")); FieldMappings.Add(FieldType.Date, new FieldMapInfo("date")); FieldMappings.Add(FieldType.Int, new FieldMapInfo("INTEGER")); FieldMappings.Add(FieldType.Long, new FieldMapInfo("bigint")); FieldMappings.Add(FieldType.Real, new FieldMapInfo("real")); FieldMappings.Add(FieldType.Time, new FieldMapInfo("INTERVAL")); FieldMappings.Add(FieldType.Money, new FieldMapInfo("NUMERIC")); FieldMappings.Add(FieldType.String, new FieldMapInfo("character varying")); FieldMappings.Add(FieldType.Default, new FieldMapInfo("character varying")); FieldMappings.Add(FieldType.UnicodeString, new FieldMapInfo("character varying")); FieldMappings.Add(FieldType.Text, new FieldMapInfo("text")); FieldMappings.Add(FieldType.UnicodeText, new FieldMapInfo("text")); }
private void ExecuteFieldMapBehaviors() { // Auto-infer IsIdentity if no field is declared as primary key // and no field is declared as identity and one member is named // "ID" and that member is an int or a long. bool hasPkOrIdent = false; DataModelColumnAttribute idFieldMapping = null; string typename = null; foreach (var field_kvp in FieldMappings) { var field = field_kvp.Value; if (!field.IsForeignKey) { if ((field.IsIdentity && field.IsIdentityDefined) || (field.IsPrimaryKey && field.IsPrimaryKeyDefined)) { hasPkOrIdent = true; } if (typename == null) { typename = field.TargetMember.DeclaringType.Name.ToLower(); } var propname = field.TargetMember.Name.ToLower(); if (propname == "id" || propname == typename + "id" || propname == typename + "_id") { idFieldMapping = field; } } } if (!hasPkOrIdent && idFieldMapping != null && (idFieldMapping.DbType == DbType.Int32 || idFieldMapping.DbType == DbType.Int64)) { idFieldMapping.IsIdentity = true; } // Auto-infer a dictionary entry placeholder for foreign entity mappings // with no referenced foreign key column foreach (var fk in ForeignModelMappings) { //if (fk.Value.TargetMemberType.IsOrInherits(typeof(IEnumerable))) continue; var tmt = GetEntityType(fk.Value.TargetMemberType); var ttmap = GetEntityMapping(tmt); var ff = ttmap != null ? ttmap.GetFieldMappingByDbColumnName(fk.Value.RelatedTableColumn) : null; if (FieldMappings.ToList().Exists(p => p .Value.ColumnName.ToLower() == fk.Value.LocalColumn.ToLower())) { continue; } var fm = new DataModelColumnAttribute(); if (ff != null) { ff.CopyDeltaTo(fm); fm.ColumnName = fk.Value.LocalColumn; fm.DbType = fk.Value.LocalColumnDbType; fm.SqlDbType = fk.Value.LocalColumnSqlDbType; fm.ColumnSize = fk.Value.LocalColumnSize; fm.IsNullable = fk.Value.LocalColumnIsNullable; fm.TargetMember = fk.Value.TargetMember; fm.TargetMemberType = fk.Value.TargetMemberType; fm.IsPrimaryKey = false; fm.IsIdentity = false; FieldMappings.Add("field:" + fk.Value.LocalColumn, fm); } _FieldMapBehaviorsExecuted = true; } // predetermine NULLables based on CLR nullability foreach (var field_kvp in FieldMappings) { var field = field_kvp.Value; if (!field.IsNullableDefined) { var memtype = field.TargetMemberType; bool nullable = !memtype.IsValueType; if (memtype.IsGenericType && memtype.GetGenericTypeDefinition() == typeof(Nullable <>)) { memtype = memtype.GetGenericArguments()[0]; nullable = true; } field.IsNullable = (memtype.IsValueType || memtype == typeof(string)) && nullable && !field.IsPrimaryKey; } } }
protected ClassMapping <T> Map(string field, string property) { FieldMappings.Add(field, property); return(this); }
public void AddFieldMappings(Expression <Func <bool> > mapping, Func <object, object> save = null, Func <object, object> load = null) { FieldMappings.Add(mapping); Converters.Add(mapping, new Func <object, object>[] { save, load }); }