public void MapColumn(ColumnBase column, string name = null) { if (!_handledIdentity) { _handledIdentity = true; if (_bp.From == null) { throw new NotImplementedException("Must have an Entity - did you forget to set the From"); } if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0) { throw new NotImplementedException("Entity must have a primary key"); } if (_bp.From.PrimaryKeyColumns.Length == 1) { _idColumn = _bp.From.PrimaryKeyColumns[0]; } else { _idColumn = new TextColumn("id").BindValue(() => { var x = new SeperatedBuilder(); foreach (var item in _bp.From.PrimaryKeyColumns) { x.Add(DataItem.FixValueTypes(item.Value)); } return(x.ToString()); }); Columns.Add(_bp.From.PrimaryKeyColumns); Columns.Add(_idColumn); IgnoreUpdateOf(_idColumn); } } if (name == null) { if (UseClassMemberName) { if (column.Entity != null) { foreach (var item in column.Entity.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (item.GetValue(column.Entity) == column) { name = item.Name; } } } else { foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (item.GetValue(this) == column) { name = item.Name; } } } if (name != null) { if (name.Length > 1) { name = name[0].ToString().ToLower() + name.Substring(1); } if (name.Length == 1) { name = name.ToLower(); } } if (column.Entity != null && column.Entity != From) { foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (item.GetValue(this) == column.Entity) { name = item.Name + "_" + name; name = name[0].ToString().ToLower() + name.Substring(1); } } } } if (name == null) { name = column.Caption; if (NameFixer.HasHebrewInIt(name) && !string.IsNullOrEmpty(column.Name) && UseNameInsteadOfCaptionForHebrew) { name = column.Name; } name = SeparateWordsAndCasing(name); } } if (column == _idColumn) { name = "id"; } name = NameFixer.fixName(name); var orgName = name; int i = 1; while (_colsPerKey.ContainsKey(name.ToUpper())) { name = orgName + (i++).ToString(); } var cv = new ColumnInViewModel(name, () => column.Value, v => { Caster.Cast(column, v, new setValueForColumn()); }, column); _colMap.Add(column, cv); _colsPerKey.Add(name.ToUpper(), cv); _columns.Add(cv); Columns.Add(column); }
internal void SaveTo(DataItem x) { x.Set(_key, _getValueFromRow()); }
public void MapColumn(ColumnBase column, string name = null) { if (!_handledIdentity) { _handledIdentity = true; if (_bp.From == null) { throw new NotImplementedException("Must have an Entity - did you forget to set the From"); } if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0) { throw new NotImplementedException("Entity must have a primary key"); } if (_bp.From.PrimaryKeyColumns.Length == 1) { _idColumn = _bp.From.PrimaryKeyColumns[0]; } else { _idColumn = new TextColumn("id").BindValue(() => { var x = new SeperatedBuilder(); foreach (var item in _bp.From.PrimaryKeyColumns) { x.Add(DataItem.FixValueTypes(item.Value)); } return(x.ToString()); }); Columns.Add(_bp.From.PrimaryKeyColumns); Columns.Add(_idColumn); IgnoreUpdateOf(_idColumn); } } if (name == null) { name = column.Caption; if (NameFixer.HasHebrewInIt(name) && !string.IsNullOrEmpty(column.Name)) { name = column.Name; } name = SeparateWordsAndCasing(name); } if (column == _idColumn) { name = "id"; } name = NameFixer.fixName(name); var orgName = name; int i = 1; while (_colsPerKey.ContainsKey(name.ToUpper())) { name = orgName + (i++).ToString(); } var cv = new ColumnInViewModel(name, () => column.Value, v => { Caster.Cast(column, v, new setValueForColumn()); }, column); _colMap.Add(column, cv); _colsPerKey.Add(name.ToUpper(), cv); _columns.Add(cv); Columns.Add(column); }