public (string statement, CommandParameterValues parameterValues) CreateDelete(IId document) { var mapping = mappings.Get(document.GetType()); var id = (string)mapping.IdColumn.ReaderWriter.Read(document); return(CreateDeleteById(mapping, id)); }
public void SelectNodeById(IId iId) { if (iId == null) { return; } int nodeType = 0; var r = FindNode(iId.Id, iId.GetType()); if (r != null) { //TreeView1.SelectedItem = r; r.IsSelected = true; ExpandParent(r); } }
public (DocumentMap, string, CommandParameterValues) CreateUpdate(IId document, string tableHint) { var mapping = mappings.Get(document.GetType()); var updates = string.Join(", ", mapping.IndexedColumns.Select(c => "[" + c.ColumnName + "] = @" + c.ColumnName).Union(new[] { $"[JSON] = @{JsonVariableName}" })); var statement = $"UPDATE dbo.[{mapping.TableName}] {tableHint ?? ""} SET {updates} WHERE [{mapping.IdColumn.ColumnName}] = @{IdVariableName}"; var parameters = GetDocumentParameters( m => throw new Exception("Cannot update a document if it does not have an ID"), document, mapping, null ); statement = AppendRelatedDocumentStatementsForUpdate(statement, parameters, mapping, document); return(mapping, statement, parameters); }
/// <summary> /// Inserts object into database if it doesn't already exist /// </summary> /// <returns>True if the object was inserted, otherwise false</returns> public static async Task <bool> Upload( IId obj, IDataApiClient dataApiClient, bool overwriteIfExists = false) { if (overwriteIfExists) { await dataApiClient.ReplaceAsync(obj, obj.Id); return(true); } var exists = await dataApiClient.ExistsAsync(obj.GetType().Name, obj.Id); if (!exists) { await dataApiClient.InsertAsync(obj, obj.Id); } return(!exists); }
/// <summary> /// 获取可视信息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static string GetText(this IId entity, Func <IId, string> textFactory = null) { if (textFactory != null) { return(textFactory(entity)); } if (entity is IText) { return(((IText)entity).Text); } var pi = entity.GetType().GetPropertyAny(typeof(string), "DisplayName", "Name", "Description"); if (pi != null) { return(pi.GetValue(entity) as string); } return(entity.ToString()); }
public static ShortId FromIId(string shortId, IId iid) { return(new ShortId(shortId, iid.GetType().Name, iid.Id)); }
public bool Equals(IId other) { if (other == null) { return(false); } if (object.ReferenceEquals(this, other)) { return(true); } if (!(other is DMTId)) { logger.Error("Comparing incompatible IId implementations. {0} and {1}", typeof(DMTId), other.GetType()); return(false); } DMTId other2 = (DMTId)other; return(this.value.Equals(other2.value)); }
public static DataReference FromIId(IId obj) { return(new DataReference(obj.GetType().Name, obj.Id)); }