【繁星Code】如何在EF将实体注释写入数据库中
最近在项目中需要把各个字段的释义写到数据库中,该项目已经上线很长时间了,数据库中的字段没有上千也有上百个,要是一个项目一个项目打开然后再去找对应字段查看什么意思,估计要到明年过年了。由于项目中使用EntityFramework,本身这个项目只有手动设置字段注释的功能,Coder平时写代码的时候都懒得写注释,更别提能在配置数据库的时候将注释配置进去,所以如何在EF中自动将实体注释写入数据库,减轻Coder的压力(ru he tou lan)尤为重要。gitee地址:https://gitee.com/lbqman/Blog20210206.git 。下面进入正题。
一、实现思路
/// <summary>Configures a comment to be applied to the column</summary>
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="comment"> The comment for the column. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder<TProperty> HasComment<TProperty>(
[NotNull] this PropertyBuilder<TProperty> propertyBuilder,
[CanBeNull] string comment)
{
return (PropertyBuilder<TProperty>) propertyBuilder.HasComment(comment);
}
- 如何获取当前配置的字段;
- 加载Xml,并根据字段获取对应的注释;
- 如何将枚举的各项信息都放入注释中;
二、实现方法
1.如何获取当前配置的字段
public virtual PropertyBuilder<TProperty> Property<TProperty>(
[NotNull] Expression<Func<TEntity, TProperty>> propertyExpression);
public static PropertyBuilder<TProperty> SummaryProperty<TEntity, TProperty>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
Expression<Func<TEntity, TProperty>> propertyExpression)
where TEntity : class
public static MemberInfo GetMember<T, TProperty>(this Expression<Func<T, TProperty>> expression)
{
MemberExpression memberExp;
if (expression.Body is UnaryExpression unaryExpression)
memberExp = unaryExpression.Operand as MemberExpression;
else
memberExp = expression.Body as MemberExpression;
return memberExp?.Member;
}
2.加载Xml,并根据字段获取对应的注释
/// <summary>
/// xml注释获取器
/// </summary>
internal static class SummaryXmlCacheProvider
{
#region TClass
/// <summary>
/// 根据类型初始化该类所在程序集的xml
/// </summary>
/// <typeparam name="TClass"></typeparam>
internal static void InitSummaryXml<TClass>()
{
var assembly = Assembly.GetAssembly(typeof(TClass));
SerializeXmlFromAssembly(assembly);
}
/// <summary>
/// 根据类型获取该类所在程序集的xml
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <returns></returns>
internal static Dictionary<string, string> GetSummaryXml<TClass>()
{
var assembly = Assembly.GetAssembly(typeof(TClass));
return SummaryCache[assembly];
}
/// <summary>
/// 获取该类在xml的key
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <returns></returns>
internal static string GetClassTypeKey<TClass>()
{
return TableSummaryRuleProvider.TypeSummaryKey(typeof(TClass).FullName);
}
#endregion
#region TProperty
/// <summary>
/// 根据类型以及字段初始化该类所在程序集的xml
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
internal static void InitSummaryXml<TClass, TProperty>(Expression<Func<TClass, TProperty>> propertyExpression)
{
var propertyAssembly = GetPropertyAssembly(propertyExpression);
SerializeXmlFromAssembly(propertyAssembly);
}
/// <summary>
/// 根据类型以及字段获取该类所在程序集的xml
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
/// <returns></returns>
internal static Dictionary<string, string> GetSummaryXml<TClass, TProperty>(
Expression<Func<TClass, TProperty>> propertyExpression)
{
var propertyAssembly = GetPropertyAssembly(propertyExpression);
return SummaryCache[propertyAssembly];
}
/// <summary>
/// 获取该类以及字段所在xml的key
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
/// <returns></returns>
internal static string GetPropertyTypeKey<TClass, TProperty>(
Expression<Func<TClass, TProperty>> propertyExpression)
{
var memberName = propertyExpression.GetMember().Name;
var propertyInfo = GetPropertyInfo(propertyExpression);
var propertyKey =
$"{propertyInfo.DeclaringType.Namespace}.{propertyInfo.DeclaringType.Name}.{memberName}";
return PropertySummaryRuleProvider.PropertyTypeSummaryKey(propertyKey);
}
#endregion
#region TEnum
/// <summary>
/// 获取枚举字段的描述信息
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
/// <returns></returns>
internal static string GetEnumPropertyDescription<TClass, TProperty>(Expression<Func<TClass, TProperty>> propertyExpression)
{
var propertyInfo = GetPropertyInfo(propertyExpression);
if (!propertyInfo.PropertyType.IsEnum)
return string.Empty;
var enumType = propertyInfo.PropertyType;
SerializeXmlFromAssembly(enumType.Assembly);
var propertySummaryDic = SummaryCache[enumType.Assembly];
var enumNames = enumType.GetEnumNames();
var enumDescDic = enumType.GetNameAndValues();
var enumSummaries = new List<string>();
foreach (var enumName in enumNames)
{
var propertyEnumKey = PropertySummaryRuleProvider.EnumTypeSummaryKey($"{enumType.FullName}.{enumName}");
var enumSummary = propertySummaryDic.ContainsKey(propertyEnumKey)
? propertySummaryDic[propertyEnumKey]
: string.Empty;
var enumValue = enumDescDic[enumName];
enumSummaries.Add(PropertySummaryRuleProvider.EnumTypeSummaryFormat(enumValue,enumName,enumSummary));
}
return string.Join(";", enumSummaries);
}
#endregion
/// <summary>
/// 根据表达式获取属性所在的程序集
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
/// <returns></returns>
private static Assembly GetPropertyAssembly<TClass, TProperty>(
Expression<Func<TClass, TProperty>> propertyExpression)
{
var propertyInfo = GetPropertyInfo(propertyExpression);
var propertyAssembly = propertyInfo.Module.Assembly;
return propertyAssembly;
}
/// <summary>
/// 根据表达式获取字段属性
/// </summary>
/// <typeparam name="TClass"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="propertyExpression"></param>
/// <returns></returns>
private static PropertyInfo GetPropertyInfo<TClass, TProperty>(
Expression<Func<TClass, TProperty>> propertyExpression)
{
var entityType = typeof(TClass);
var memberName = propertyExpression.GetMember().Name;
var propertyInfo = entityType.GetProperty(memberName, typeof(TProperty));
if (propertyInfo == null || propertyInfo.DeclaringType == null)
throw new ArgumentNullException($"this property {memberName} is not belong to {entityType.Name}");
return propertyInfo;
}
/// <summary>
/// 根据程序集初始化xml
/// </summary>
/// <param name="assembly"></param>
private static void SerializeXmlFromAssembly(Assembly assembly)
{
var assemblyPath = assembly.Location;
var lastIndexOf = assemblyPath.LastIndexOf(".dll", StringComparison.Ordinal);
var xmlPath = assemblyPath.Remove(lastIndexOf, 4) + ".xml";
if (SummaryCache.ContainsKey(assembly))
return;
var xmlDic = new Dictionary<string, string>();
if (!File.Exists(xmlPath))
{
Console.WriteLine($"未能加载xml文件,原因:xml文件不存在,path:{xmlPath}");
SummaryCache.Add(assembly, xmlDic);
return;
}
var doc = new XmlDocument();
doc.Load(xmlPath);
var members = doc.SelectNodes("doc/members/member");
if (members == null)
{
Console.WriteLine($"未能加载xml文件,原因:doc/members/member节点不存在");
SummaryCache.Add(assembly, xmlDic);
return;
}
foreach (XmlElement member in members)
{
var name = member.Attributes["name"].InnerText.Trim();
if (string.IsNullOrWhiteSpace(name))
continue;
xmlDic.Add(name, member.SelectSingleNode("summary")?.InnerText.Trim());
}
SummaryCache.Add(assembly, xmlDic);
}
/// <summary>
/// xml注释缓存
/// </summary>
private static Dictionary<Assembly, Dictionary<string, string>> SummaryCache { get; } =
new Dictionary<Assembly, Dictionary<string, string>>();
}
3.如何将枚举的各项信息都放入注释中
public static PropertyBuilder<TProperty> SummaryProperty<TEntity, TProperty>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
Expression<Func<TEntity, TProperty>> propertyExpression)
where TEntity : class
{
SummaryXmlCacheProvider.InitSummaryXml(propertyExpression);
var entitySummaryDic = SummaryXmlCacheProvider.GetSummaryXml(propertyExpression);
var propertyKey = SummaryXmlCacheProvider.GetPropertyTypeKey(propertyExpression);
var summary = entitySummaryDic.ContainsKey(propertyKey) ? entitySummaryDic[propertyKey] : string.Empty;
var enumDescription = SummaryXmlCacheProvider.GetEnumPropertyDescription(propertyExpression);
summary = string.IsNullOrWhiteSpace(enumDescription) ? summary : $"{summary}:{enumDescription}";
return string.IsNullOrWhiteSpace(summary)
? entityTypeBuilder.Property(propertyExpression)
: entityTypeBuilder.Property(propertyExpression).HasComment(summary);
}
public static EntityTypeBuilder<TEntity> SummaryToTable<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder, bool hasTableComment = true,
Func<string> tablePrefix = null)
where TEntity : class
{
var tableName = GetTableName<TEntity>(tablePrefix);
return hasTableComment
? entityTypeBuilder.ToTable(tableName)
.SummaryHasComment()
: entityTypeBuilder.ToTable(tableName);
}
public static EntityTypeBuilder<TEntity> SummaryHasComment<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder) where TEntity : class
{
SummaryXmlCacheProvider.InitSummaryXml<TEntity>();
var entityDic = SummaryXmlCacheProvider.GetSummaryXml<TEntity>();
var tableKey = SummaryXmlCacheProvider.GetClassTypeKey<TEntity>();
var summary = entityDic.ContainsKey(tableKey) ? entityDic[tableKey] : string.Empty;
return string.IsNullOrWhiteSpace(summary) ? entityTypeBuilder : entityTypeBuilder.HasComment(summary);
}
private static string GetTableName<TEntity>(Func<string> tablePrefix)
{
return typeof(TEntity).Name.Replace("Entity", $"Tb{tablePrefix?.Invoke()}");
}
三、效果展示
public partial class InitDb : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TbGood",
columns: table => new
{
Id = table.Column<long>(nullable: false, comment: "主键")
.Annotation("SqlServer:Identity", "1, 1"),
CreateTime = table.Column<DateTime>(nullable: false, comment: "创建时间"),
CreateName = table.Column<string>(maxLength: 64, nullable: false, comment: "创建人姓名"),
UpdateTime = table.Column<DateTime>(nullable: true, comment: "更新时间"),
UpdateName = table.Column<string>(maxLength: 64, nullable: true, comment: "更新人姓名"),
Name = table.Column<string>(maxLength: 64, nullable: false, comment: "商品名称"),
GoodType = table.Column<int>(nullable: false, comment: "物品类型:(0,Electronic) 电子产品;(1,Clothes) 衣帽服装;(2,Food) 食品;(3,Other) 其他物品"),
Description = table.Column<string>(maxLength: 2048, nullable: true, comment: "物品描述"),
Store = table.Column<int>(nullable: false, comment: "储存量")
},
constraints: table =>
{
table.PrimaryKey("PK_TbGood", x => x.Id);
},
comment: "商品实体类");
migrationBuilder.CreateTable(
name: "TbOrder",
columns: table => new
{
Id = table.Column<long>(nullable: false, comment: "主键")
.Annotation("SqlServer:Identity", "1, 1"),
CreateTime = table.Column<DateTime>(nullable: false, comment: "创建时间"),
CreateName = table.Column<string>(maxLength: 64, nullable: false, comment: "创建人姓名"),
UpdateTime = table.Column<DateTime>(nullable: true, comment: "更新时间"),
UpdateName = table.Column<string>(maxLength: 64, nullable: true, comment: "更新人姓名"),
GoodId = table.Column<long>(nullable: false, comment: "商品Id"),
OrderStatus = table.Column<int>(nullable: false, comment: "订单状态:(0,Ordered) 已下单;(1,Payed) 已付款;(2,Complete) 已付款;(3,Cancel) 已取消"),
OrderTime = table.Column<DateTime>(nullable: false, comment: "下订单时间"),
Address = table.Column<string>(maxLength: 2048, nullable: false, comment: "订单地址"),
UserName = table.Column<string>(maxLength: 16, nullable: false, comment: "收件人姓名"),
TotalAmount = table.Column<decimal>(nullable: false, comment: "总金额")
},
constraints: table =>
{
table.PrimaryKey("PK_TbOrder", x => x.Id);
},
comment: "订单实体类");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TbGood");
migrationBuilder.DropTable(
name: "TbOrder");
}
}
四、写在最后
.wiz-editor-body .wiz-code-container { position: relative; padding: 8px 0; margin: 5px 0; text-indent: 0; text-align: left }
.CodeMirror { font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; color: rgba(0, 0, 0, 1); font-size: 0.875rem }
.wiz-editor-body .wiz-code-container .CodeMirror div { margin-top: 0; margin-bottom: 0 }
.CodeMirror-lines { padding: 4px 0 }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { padding: 0 4px }
.CodeMirror pre.CodeMirror-line { min-height: 24px }
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { background-color: rgba(255, 255, 255, 1) }
.CodeMirror-gutters { border-right: 1px solid rgba(221, 221, 221, 1); background-color: rgba(247, 247, 247, 1); white-space: nowrap }
.CodeMirror-linenumbers { }
.CodeMirror-linenumber { padding: 0 3px 0 5px; min-width: 20px; text-align: right; color: rgba(153, 153, 153, 1); white-space: nowrap }
.CodeMirror-guttermarker { color: rgba(0, 0, 0, 1) }
.CodeMirror-guttermarker-subtle { color: rgba(153, 153, 153, 1) }
.CodeMirror-cursor { border-left: 1px solid rgba(0, 0, 0, 1); border-right: none; width: 0 }
.CodeMirror div.CodeMirror-secondarycursor { border-left: 1px solid rgba(192, 192, 192, 1) }
.cm-fat-cursor .CodeMirror-cursor { width: auto; border: 0 !important; background: rgba(119, 238, 119, 1) }
.cm-fat-cursor div.CodeMirror-cursors { z-index: 1 }
.cm-fat-cursor-mark { background-color: rgba(20, 255, 20, 0.5); -webkit-animation: blink 1.06s steps(1) infinite; -moz-animation: blink 1.06s steps(1) infinite; animation: 1.06s step-end infinite blink }
.cm-animate-fat-cursor { width: auto; border: 0; -webkit-animation: blink 1.06s steps(1) infinite; -moz-animation: blink 1.06s steps(1) infinite; animation: 1.06s step-end infinite blink; background-color: rgba(119, 238, 119, 1) }
@-moz-keyframes blink { 0% {} 50% { background-color: transparent; } 100% {}}
@-webkit-keyframes blink { 0% {} 50% { background-color: transparent; } 100% {}}
@keyframes blink { 0% { } 50% { background-color: rgba(0, 0, 0, 0) } 100% { } }
.CodeMirror-overwrite .CodeMirror-cursor { }
.cm-tab { display: inline-block }
.CodeMirror-rulers { position: absolute; left: 0; right: 0; top: -50px; bottom: -20px; overflow: hidden }
.CodeMirror-ruler { border-left: 1px solid rgba(204, 204, 204, 1); top: 0; bottom: 0; position: absolute }
.cm-s-default .cm-header { color: rgba(0, 0, 255, 1) }
.cm-s-default .cm-quote { color: rgba(0, 153, 0, 1) }
.cm-negative { color: rgba(221, 68, 68, 1) }
.cm-positive { color: rgba(34, 153, 34, 1) }
.cm-header, .cm-strong { font-weight: bold }
.cm-em { font-style: italic }
.cm-link { text-decoration: underline }
.cm-strikethrough { text-decoration: line-through }
.cm-s-default .cm-keyword { color: rgba(119, 0, 136, 1) }
.cm-s-default .cm-atom { color: rgba(34, 17, 153, 1) }
.cm-s-default .cm-number { color: rgba(17, 102, 68, 1) }
.cm-s-default .cm-def { color: rgba(0, 0, 255, 1) }
.cm-s-default .cm-variable, .cm-s-default .cm-punctuation, .cm-s-default .cm-property, .cm-s-default .cm-operator { }
.cm-s-default .cm-variable-2 { color: rgba(0, 85, 170, 1) }
.cm-s-default .cm-variable-3 { color: rgba(0, 136, 85, 1) }
.cm-s-default .cm-comment { color: rgba(170, 85, 0, 1) }
.cm-s-default .cm-string { color: rgba(170, 17, 17, 1) }
.cm-s-default .cm-string-2 { color: rgba(255, 85, 0, 1) }
.cm-s-default .cm-meta { color: rgba(85, 85, 85, 1) }
.cm-s-default .cm-qualifier { color: rgba(85, 85, 85, 1) }
.cm-s-default .cm-builtin { color: rgba(51, 0, 170, 1) }
.cm-s-default .cm-bracket { color: rgba(153, 153, 119, 1) }
.cm-s-default .cm-tag { color: rgba(17, 119, 0, 1) }
.cm-s-default .cm-attribute { color: rgba(0, 0, 204, 1) }
.cm-s-default .cm-hr { color: rgba(153, 153, 153, 1) }
.cm-s-default .cm-link { color: rgba(0, 0, 204, 1) }
.cm-s-default .cm-error { color: rgba(255, 0, 0, 1) }
.cm-invalidchar { color: rgba(255, 0, 0, 1) }
.CodeMirror-composing { border-bottom: 2px solid }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgba(0, 187, 0, 1) }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgba(170, 34, 34, 1) }
.CodeMirror-matchingtag { background: rgba(255, 150, 0, 0.3) }
.CodeMirror-activeline-background { background: rgba(232, 242, 255, 1) }
.CodeMirror { position: relative; background: rgba(245, 245, 245, 1) }
.CodeMirror-scroll { overflow: hidden !important; margin-bottom: 0; margin-right: -30px; padding: 16px 30px 16px 0; outline: none; position: relative }
.CodeMirror-sizer { position: relative; border-right: 30px solid rgba(0, 0, 0, 0) }
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { position: absolute; z-index: 6; display: none }
.CodeMirror-vscrollbar { right: 0; top: 0; overflow-x: hidden; overflow-y: scroll }
.CodeMirror-hscrollbar { bottom: 0; left: 0 !important; overflow-y: hidden; overflow-x: scroll; pointer-events: auto !important; outline: none }
.CodeMirror-scrollbar-filler { right: 0; bottom: 0 }
.CodeMirror-gutter-filler { left: 0; bottom: 0 }
.CodeMirror-gutters { position: absolute; left: 0; top: 0; min-height: 100%; z-index: 3 }
.CodeMirror-gutter { white-space: normal; height: 100%; display: inline-block; vertical-align: top; margin-bottom: -30px }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; border: none !important }
.CodeMirror-gutter-background { position: absolute; top: 0; bottom: 0; z-index: 4 }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4 }
.CodeMirror-gutter-wrapper ::selection { background-color: rgba(0, 0, 0, 0) }
{ background-color: rgba(0, 0, 0, 0) }
.CodeMirror-lines { cursor: text; min-height: 1px }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; border-width: 0; background: rgba(0, 0, 0, 0); font-family: inherit; font-size: inherit; margin: 0; white-space: pre; word-wrap: normal; line-height: inherit; color: inherit; z-index: 2; position: relative; overflow: visible; -webkit-tap-highlight-color: transparent; -webkit-font-variant-ligatures: contextual; font-variant-ligatures: contextual }
.CodeMirror-wrap pre.CodeMirror-line, .CodeMirror-wrap pre.CodeMirror-line-like { word-wrap: break-word; white-space: pre-wrap; word-break: normal }
.CodeMirror-linebackground { position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: 0 }
.CodeMirror-linewidget { position: relative; z-index: 2; padding: 0.1px }
.CodeMirror-widget { }
.CodeMirror-rtl pre { direction: rtl }
.CodeMirror-code { outline: none }
.CodeMirror-scroll, .CodeMirror-sizer, .CodeMirror-gutter, .CodeMirror-gutters, .CodeMirror-linenumber { -moz-box-sizing: content-box; box-sizing: content-box }
.CodeMirror-measure { position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden }
.CodeMirror-cursor { position: absolute; pointer-events: none }
.CodeMirror-measure pre { position: static }
div.CodeMirror-cursors { visibility: hidden; position: relative; z-index: 3 }
div.CodeMirror-dragcursors { visibility: visible }
.CodeMirror-focused div.CodeMirror-cursors { visibility: visible }
.CodeMirror-selected { background: rgba(217, 217, 217, 1) }
.CodeMirror-focused .CodeMirror-selected { background: rgba(215, 212, 240, 1) }
.CodeMirror-crosshair { cursor: crosshair }
.CodeMirror-line::selection, .CodeMirror-line>span::selection, .CodeMirror-line>span>span::selection { background: rgba(215, 212, 240, 1) }
{ background: rgba(215, 212, 240, 1) }
.cm-searching { background: rgba(255, 255, 0, 0.4) }
.cm-force-border { padding-right: 0.1px }
@media print { .CodeMirror div.CodeMirror-cursors { visibility: hidden } }
.cm-tab-wrap-hack:after { content: "" }
span.CodeMirror-selectedtext { }
.CodeMirror-activeline-background, .CodeMirror-selected { transition: visibility 0ms 100ms }
.CodeMirror-blur .CodeMirror-activeline-background, .CodeMirror-blur .CodeMirror-selected { visibility: hidden }
.CodeMirror-blur .CodeMirror-matchingbracket { color: inherit !important; outline: none !important; text-decoration: none !important }
.CodeMirror-sizer { }
.cm-s-material.CodeMirror { background-color: rgba(38, 50, 56, 1); color: rgba(233, 237, 237, 1) }
.cm-s-material .CodeMirror-gutters { background: rgba(38, 50, 56, 1); color: rgba(83, 127, 126, 1); border: none }
.cm-s-material .CodeMirror-guttermarker, .cm-s-material .CodeMirror-guttermarker-subtle, .cm-s-material .CodeMirror-linenumber { color: rgba(83, 127, 126, 1) }
.cm-s-material .CodeMirror-cursor { border-left: 1px solid rgba(248, 248, 240, 1) }
.cm-s-material div.CodeMirror-selected { background: rgba(255, 255, 255, 0.15) }
.cm-s-material.CodeMirror-focused div.CodeMirror-selected { background: rgba(255, 255, 255, 0.1) }
.cm-s-material .CodeMirror-line::selection, .cm-s-material .CodeMirror-line>span::selection, .cm-s-material .CodeMirror-line>span>span::selection { background: rgba(255, 255, 255, 0.1) }
{ background: rgba(255, 255, 255, 0.1) }
.cm-s-material .CodeMirror-activeline-background { background: rgba(0, 0, 0, 0) }
.cm-s-material .cm-keyword { color: rgba(199, 146, 234, 1) }
.cm-s-material .cm-operator { color: rgba(233, 237, 237, 1) }
.cm-s-material .cm-variable-2 { color: rgba(128, 203, 196, 1) }
.cm-s-material .cm-variable-3 { color: rgba(130, 177, 255, 1) }
.cm-s-material .cm-builtin { color: rgba(222, 203, 107, 1) }
.cm-s-material .cm-atom { color: rgba(247, 118, 105, 1) }
.cm-s-material .cm-number { color: rgba(247, 118, 105, 1) }
.cm-s-material .cm-def { color: rgba(233, 237, 237, 1) }
.cm-s-material .cm-string { color: rgba(195, 232, 141, 1) }
.cm-s-material .cm-string-2 { color: rgba(128, 203, 196, 1) }
.cm-s-material .cm-comment { color: rgba(84, 110, 122, 1) }
.cm-s-material .cm-variable { color: rgba(130, 177, 255, 1) }
.cm-s-material .cm-tag { color: rgba(128, 203, 196, 1) }
.cm-s-material .cm-meta { color: rgba(128, 203, 196, 1) }
.cm-s-material .cm-attribute { color: rgba(255, 203, 107, 1) }
.cm-s-material .cm-property { color: rgba(128, 203, 174, 1) }
.cm-s-material .cm-qualifier { color: rgba(222, 203, 107, 1) }
.cm-s-material .cm-variable-3 { color: rgba(222, 203, 107, 1) }
.cm-s-material .cm-tag { color: rgba(255, 83, 112, 1) }
.cm-s-material .cm-error { color: rgba(255, 255, 255, 1); background-color: rgba(236, 95, 103, 1) }
.cm-s-material .CodeMirror-matchingbracket { text-decoration: underline; color: rgba(255, 255, 255, 1) !important }
html, .wiz-editor-body { font-size: 12pt }
.wiz-editor-body { font-family: Helvetica, "Hiragino Sans GB", "微软雅黑", "Microsoft YaHei UI", SimSun, SimHei, arial, sans-serif; line-height: 1.7; margin: 0 auto; position: relative; padding: 20px 16px }
.wiz-editor-body h1, .wiz-editor-body h2, .wiz-editor-body h3, .wiz-editor-body h4, .wiz-editor-body h5, .wiz-editor-body h6 { margin: 1.25rem 0 0.625rem; padding: 0; font-weight: bold }
.wiz-editor-body h1 { font-size: 1.67rem }
.wiz-editor-body h2 { font-size: 1.5rem }
.wiz-editor-body h3 { font-size: 1.25rem }
.wiz-editor-body h4 { font-size: 1.17rem }
.wiz-editor-body h5 { font-size: 1rem }
.wiz-editor-body h6 { font-size: 1rem; color: rgba(119, 119, 119, 1); margin: 1rem 0 }
.wiz-editor-body div, .wiz-editor-body p, .wiz-editor-body ul, .wiz-editor-body ol, .wiz-editor-body dl, .wiz-editor-body li { margin: 8px 0 0 }
.wiz-editor-body blockquote, .wiz-editor-body table, .wiz-editor-body pre, .wiz-editor-body code { margin: 8px 0 }
.wiz-editor-body .CodeMirror pre { margin: 0 }
.wiz-editor-body a { word-wrap: break-word; text-decoration-skip-ink: none }
.wiz-editor-body ul, .wiz-editor-body ol { padding-left: 2rem }
.wiz-editor-body ol.wiz-list-level1>li { list-style-type: decimal }
.wiz-editor-body ol.wiz-list-level2>li { list-style-type: lower-latin }
.wiz-editor-body ol.wiz-list-level3>li { list-style-type: lower-roman }
.wiz-editor-body li.wiz-list-align-style { list-style-position: inside; margin-left: -1em }
.wiz-editor-body blockquote { padding: 0 12px }
.wiz-editor-body blockquote>:first-child { margin-top: 0 }
.wiz-editor-body blockquote>:last-child { margin-bottom: 0 }
.wiz-editor-body img { border: 0; max-width: 100%; height: auto !important; margin: 2px 0; padding: 2px; vertical-align: bottom }
.wiz-editor-body table { border-collapse: collapse; border: 1px solid rgba(167, 175, 188, 1) }
.wiz-editor-body td, .wiz-editor-body th { padding: 4px 8px; border-collapse: collapse; border: 1px solid rgba(167, 175, 188, 1); min-height: 28px; box-sizing: border-box }
.wiz-editor-body td>div:first-child { margin-top: 0 }
.wiz-editor-body td>div:last-child { margin-bottom: 0 }
.wiz-editor-body img.wiz-svg-image { box-shadow: 1px 1px 4px rgba(232, 232, 232, 1) }
.wiz-editor-body .wiz-image-container { margin: 0; max-width: 100%; display: inline-flex; flex-direction: column }
.wiz-editor-body .wiz-image-container .wiz-image-title { display: inline-block; text-align: center; color: rgba(167, 175, 188, 1); line-height: 18px; font-size: 12px; min-height: 18px; width: 100%; white-space: normal }
.wiz-hide { display: none !important }
.wiz-editor-body.wiz-editor-outline { padding-right: 0; padding-left: 0 }
.wiz-editor-body.wiz-editor-outline .outline-container { margin: 0; padding: 0; line-height: 1.5 }
.wiz-editor-body.wiz-editor-outline .outline-container div { margin: 0 }
.wiz-editor-body.wiz-editor-outline .node { margin: 0; padding: 0 }
.wiz-editor-body.wiz-editor-outline .outline-container>.node { margin-right: 24px; margin-left: 30px }
.wiz-editor-body.wiz-editor-outline .node.collapsed .children { display: none }
.wiz-editor-body.wiz-editor-outline .node .row { position: relative; padding-left: 26px }
.wiz-editor-body.wiz-editor-outline .node .operator-container { width: 36px; position: absolute; top: 4px; left: -18px }
.wiz-editor-body.wiz-editor-outline .node .operator-bar { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center }
.wiz-editor-body.wiz-editor-outline .node .switch { width: 18px; height: 18px; display: flex; flex-direction: column; align-items: center; overflow: hidden }
.wiz-editor-body.wiz-editor-outline .node .switch i { font-size: 20px; position: relative; left: -1px; top: -1px }
.wiz-editor-body.wiz-editor-outline .node .switch.active { cursor: pointer; color: rgba(0, 0, 0, 0); transition: transform 200ms ease 0s }
.wiz-editor-body.wiz-editor-outline .node.collapsed .switch.active { transform: rotateY(-90deg) }
.wiz-editor-body.wiz-editor-outline .node .row:hover .switch.active { color: rgba(80, 95, 121, 1) }
.wiz-editor-body.wiz-editor-outline .node .dot { display: flex; align-items: center; justify-content: center; border-radius: 100%; width: 18px; height: 18px }
.wiz-editor-body.wiz-editor-outline .node.collapsed .dot { background-color: rgba(80, 95, 121, 0.15) }
.wiz-editor-body.wiz-editor-outline .node .dot-icon { background-color: rgba(80, 95, 121, 1); border-radius: 100%; width: 6px; height: 6px }
.wiz-editor-body.wiz-editor-outline .node .child { margin-left: 8px; border-left: 1px solid rgba(230, 233, 237, 1); padding-left: 17px }
.wiz-editor-body.wiz-editor-outline .node .content { flex: 1; outline: none; padding: 4px 0 }
.wiz-editor-body.wiz-editor-outline .node div.content { font-size: 1rem }
.wiz-editor-body.wiz-editor-outline .node.complete>.row .content { text-decoration: line-through; color: rgba(167, 175, 188, 1) }
.wiz-editor-body.wiz-editor-outline .node .notes { outline: none; font-size: 0.8rem; color: rgba(167, 175, 188, 1) }
.wiz-editor-body.wiz-editor-outline .node .image { outline: none; padding-top: 4px; padding-bottom: 4px }
.wiz-editor-body.wiz-editor-outline .outline-container h1, .wiz-editor-body.wiz-editor-outline .outline-container h2, .wiz-editor-body.wiz-editor-outline .outline-container h3, .wiz-editor-body.wiz-editor-outline .outline-container h4, .wiz-editor-body.wiz-editor-outline .outline-container h5, .wiz-editor-body.wiz-editor-outline .outline-container h6 { margin: 0 }
body, .wiz-editor-body { padding-left: 48px; padding-right: 48px }
【繁星Code】如何在EF将实体注释写入数据库中的更多相关文章
- EF生成实体自动添加数据库字段注释
我们在用EF从数据库生成模型的时候,默认实体类是没有注释的,但是我们已经在数据库字段添加说明了,能不能自动把注释也拿过来? 答案是:能. 那么我们开始 首先随便开一个ASP.NET MVC项目,我 ...
- 在实体类中将数据库中数据类型为CLOB的数据转化成String类型
@Lob @Basic(fetch = FetchType.EAGER) @Column(name = "JYAQ", columnDefinition = &qu ...
- EF 解除属性映射到数据库中 NotMappedAttribute无效解决办法
可以通过NotMappedAttribute标记模型某个属性可以使该属性不必映射到数据库. public class Unicorn { public int Id { get; set; } [No ...
- EF Core 2.1 支持数据库一对一关系
在使用EF Core和设计数据库的时候,通常一对多.多对多关系使用得比较多,但是一对一关系使用得就比较少了.最近我发现实际上EF Core很好地支持了数据库的一对一关系. 数据库 我们先来看看SQL ...
- EF 操作数据库中的表
1.VS创建项目(实现数据库的增删改查.并在dataGridView中展示) 增.改通过Button,删通过快捷菜单ContextMenuStrip控件(DateGridView控件的ContextM ...
- MVC5使用EF6 Code First--创建EF数据模型(一)
此Web应用程序演示如何使用Entity Framework 6和Visual Studio 2015创建ASP.NET MVC 5应用程序.本教程使用“Code First ”即代码先行.有关如何在 ...
- Entity Framework 6 Recipes 2nd Edition(10-1)译->非Code Frist方式返回一个实体集合
存储过程 存储过程一直存在于任何一种关系型数据库中,如微软的SQL Server.存储过程是包含在数据库中的一些代码,通常为数据执行一些操作,它能为数据密集型计算提高性能,也能执行一些为业务逻辑. 当 ...
- 在Code First中使用Migrations对实体类和数据库做出变更
在Code First中使用Migrations对实体类和数据库做出变更,Mirgration包含一系列命令. 工具--库程序包管理器--程序包管理器控制台 运行命令:Enable-Migration ...
- ASP.NET没有魔法——ASP.NET MVC 与数据库之EF实体类与数据库结构
大家都知道在关系型数据库中每张表的每个字段都会有自己的属性,如:数据类型.长度.是否为空.主外键.索引以及表与表之间的关系.但对于C#编写的类来说,它的属性只有一个数据类型和类与类之间的关系,但是在M ...
随机推荐
- spark知识点_datasources
来自官网DataFrames.DataSets.SQL,即sparkSQL模块. 通过dataframe接口,sparkSQL支持多种数据源的操作.可以把dataframe注册为临时视图,也可以通过关 ...
- NOIP初赛篇——07信息编码表示
一.基本概念 编码 计算机要处理的数据除了数值数据以外,还有各类符号.图形.图像和声音等非数值数据.而计算机只能识别两个数字0,1.要使计算机能处理这些信息,首先必须要将各类信息转换成0与1表示的 ...
- 【函数分享】每日PHP函数分享(2021-1-12)
str_pad() 使用另一个字符串填充字符串为指定长度 . string str_pad ( string $input, int $pad_length[, string $pad_string= ...
- springboot项目打war包流程
目前,前后端分离的架构已成主流,因此使用springboot构建应用是非常快速的,项目发布到服务器上的时候,只需要打成一个jar包,然后通过命令 : java -jar jar包名称即可启动服务了:但 ...
- Docker安装MySQL,Redis,阿里云镜像加速
Docker安装 虚拟化容器技术.Docker基于镜像,可以秒级启动各种容器.每一种容器都是一个完整的环境,容器之间相互隔离. 如果之前安装的有其他版本,卸载旧的版本. $ sudo yum remo ...
- 9. 细节见真章,Formatter注册中心的设计很讨巧
目录 本文提纲 版本约定 你好,我是A哥(YourBatman). Spring设计了org.springframework.format.Formatter格式化器接口抽象,对格式化器进行了大一统, ...
- 2.jmeter组件介绍
jmeter默认语言设置: 1.临时设置: 进入options -- Choose Language -- 选择中文简体,设置后语言 切换成中文,重启失效 2.永久设置:进入jmeter目录下的 ...
- redis之集群一:主从
Redis的三种集群模式 Redis有三种集群模式,第一个就是主从模式,第二种"哨兵"模式,第三种是Cluster集群模式,第三种的集群模式是在Redis 3.x以后的版本才增加进 ...
- 技术实践丨React Native 项目 Web 端同构
摘要:尽管 React Native 已经进入开源的第 6 个年头,距离发布 1.0 版本依旧是遥遥无期."Learn once, write anywhere",完全不影响 Re ...
- kubernets之pod的标签的使用
一 对于kubernets里面的资源标记完成之后的使用 1 node节点标签的应用(将资源调度到特定的节点上) #kubia-gpu.ymlapiVersion: v1 kind: Pod metad ...