Прошло некоторое время, но оставив записку для других. Я достиг того, что нужно с атрибутом, и я украсил поля класса модели этим атрибутом, как я хочу.
[SqlDefaultValue(DefaultValue = "getutcdate()")]
public DateTime CreatedDateUtc { get; set; }
Получил помощь из этих двух статей:
Что я сделал:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class SqlDefaultValueAttribute : Attribute
{
public string DefaultValue { get; set; }
}
modelBuilder.Conventions.Add( new AttributeToColumnAnnotationConvention("SqlDefaultValue", (p, attributes) => attributes.Single().DefaultValue));
private void SetAnnotatedColumn(ColumnModel col)
{
AnnotationValues values;
if (col.Annotations.TryGetValue("SqlDefaultValue", out values))
{
col.DefaultValueSql = (string)values.NewValue;
}
}
Затем в конструкторе конфигурации миграции, зарегистрируйте пользовательский генератор SQL.
SetSqlGenerator("System.Data.SqlClient", new HarmonyMigrationSqlGenerator());
Попробуйте заполнить квадрат, прежде чем найти центр. Я сделал это, перебирая строки и соединяя самый левый и самый правый черный пиксель.
# Iterate through each row in the image
for row in range(img.shape[0]):
# Find the left-most and right-most pixel in the sqare
start, stop = 0, 0
for col in range(img.shape[1]):
# Find the left-most
if img[row,col] != 255 and start == 0: start = col, row
# Find the right-most
if img[row,col] != 255: stop = col, row
# If there was a pixel in that row, connect them with a line
if start != 0:
cv2.line(img, start, stop, 0, 1)