public static string UniqueConflictText(AnnotationValues uniqueAnnotation) { if (uniqueAnnotation == null) { return(string.Empty); } var uniqueText = Convert.ToString(uniqueAnnotation.NewValue, CultureInfo.InvariantCulture); OnConflictAction action; if (!uniqueText.StartsWith("OnConflict:", StringComparison.OrdinalIgnoreCase)) { return(string.Empty); } var actionText = uniqueText.Remove(0, "OnConflict:".Length).Trim(); if (!Enum.TryParse(actionText, out action)) { return(string.Empty); } if (action == OnConflictAction.None) { return(string.Empty); } return(" ON CONFLICT " + action.ToString().ToUpperInvariant()); }
public void Properties_return_expected_values() { var pair = new AnnotationValues("old", "new"); Assert.Equal("old", pair.OldValue); Assert.Equal("new", pair.NewValue); }
private void GenerateColumnDescription(AnnotationValues annotationValues, string tableName, string columnName) { if (annotationValues == null) { return; } var oldDescription = annotationValues.OldValue as string; var newDescription = annotationValues.NewValue as string; // Drop description. if (oldDescription != null) { using (var writer = Writer()) { DropColumnDescription(writer, tableName, columnName); Statement(writer); } } // Create description. if (newDescription != null) { using (var writer = Writer()) { CreateColumnDescription(writer, tableName, columnName, newDescription); Statement(writer); } } }
private void GenerateColumnDefaultValue(AnnotationValues annotationValues, string tableName, string columnName) { if (annotationValues == null) { return; } var oldValue = annotationValues.OldValue as string; var newValue = annotationValues.NewValue as string; // Drop default value. if (oldValue != null) { using (var writer = Writer()) { DropColumnDefaultConstraint(writer, tableName, columnName, null); Statement(writer); } } // Create default value. if (newValue != null) { using (var writer = Writer()) { CreateColumnDefaultConstraint(writer, tableName, columnName, null, newValue); Statement(writer); } } }
/// <summary>Sets annotation on the specified item.</summary> /// <param name="item">The item to annotate.</param> /// <param name="annotationName">The name of the annotation to set.</param> /// <param name="annotationValue">The value of the annotation to set.</param> /// <remarks>If the item already has annotation of the specified name this method will overwrite it.</remarks> public void SetAnnotation(T item, string annotationName, object annotationValue) { AnnotationValues a; if (!this.annotations.TryGetValue(item, out a)) { a = new AnnotationValues(); this.annotations[item] = a; } a.SetAnnotation(annotationName, annotationValue); }
/// <summary> /// 写入列注释 /// </summary> /// <param name="o">保存注释的对象。</param> /// <param name="f">原有生成代码的方法。</param> /// <param name="f">写入注释的方法。</param> public static void WriteComment(this IDictionary <string, AnnotationValues> o, Action gen, Action <string> f) { bool hasComment = o.ContainsKey(key); AnnotationValues comment = hasComment ? o[key] : null; //开始执行 if (hasComment) { o.Remove(key); } gen(); if (hasComment) { f(comment.NewValue as string ?? string.Empty); o.Add(key, comment); } }
public static string CollateFunctionText(AnnotationValues collateAnnotation) { if (collateAnnotation == null) { return(string.Empty); } var collateAttributeText = Convert.ToString(collateAnnotation.NewValue, CultureInfo.InvariantCulture); string collateFunction; string collateCustomFunction; if (collateAttributeText.IndexOf(':') > -1) { collateFunction = collateAttributeText.Substring(0, collateAttributeText.IndexOf(':')); collateCustomFunction = collateAttributeText.Remove(0, collateAttributeText.IndexOf(':') + 1).Trim(); } else { collateFunction = collateAttributeText; collateCustomFunction = string.Empty; } CollationFunction colatteFunctionType; if (!Enum.TryParse(collateFunction, out colatteFunctionType)) { return(string.Empty); } if (colatteFunctionType == CollationFunction.None) { return(string.Empty); } return(colatteFunctionType == CollationFunction.Custom ? " COLLATE " + collateCustomFunction : " COLLATE " + colatteFunctionType.ToString().ToUpperInvariant()); }
private bool GenerateColumnDefaultConstraint(AnnotationValues annotationValues, string tableName, string columnName) { if (annotationValues == null) { return(false); } var oldValue = annotationValues.OldValue as string; var newValue = annotationValues.NewValue as string; var modified = false; // Drop default value. if (oldValue != null) { var config = DefaultConstraintConfiguration.Deserialize(oldValue); using (var writer = Writer()) { DropColumnDefaultConstraint(writer, tableName, columnName, config.Name); Statement(writer); } modified = true; } // Create default value. if (newValue != null) { var config = DefaultConstraintConfiguration.Deserialize(newValue); using (var writer = Writer()) { CreateColumnDefaultConstraint(writer, tableName, columnName, config.Name, config.Value); Statement(writer); } modified = true; } return(modified); }