主頁 > .NET開發 > 【繁星Code】如何在EF將物體注釋寫入資料庫中

【繁星Code】如何在EF將物體注釋寫入資料庫中

2021-02-07 06:02:36 .NET開發

        最近在專案中需要把各個欄位的釋義寫到資料庫中,該專案已經上線很長時間了,資料庫中的欄位沒有上千也有上百個,要是一個專案一個專案打開然后再去找對應欄位查看什么意思,估計要到明年過年了,由于專案中使用EntityFramework,本身這個專案只有手動設定欄位注釋的功能,Coder平時寫代碼的時候都懶得寫注釋,更別提能在配置資料庫的時候將注釋配置進去,所以如何在EF中自動將物體注釋寫入資料庫,減輕Coder的壓力(ru he tou lan)尤為重要,gitee地址:https://gitee.com/lbqman/Blog20210206.git ,下面進入正題,

一、實作思路

        在FluentAPI中提供了HasComment方法,如下           11       1
    /// <summary>Configures a comment to be applied to the column</summary>
2
    /// <typeparam name="TProperty"> The type of the property being configured. </typeparam>
3
    /// <param name="propertyBuilder"> The builder for the property being configured. </param>
4
    /// <param name="comment"> The comment for the column. </param>
5
    /// <returns> The same builder instance so that multiple calls can be chained. </returns>
6
    public static PropertyBuilder<TProperty> HasComment<TProperty>(
7
      [NotNull] this PropertyBuilder<TProperty> propertyBuilder,
8
      [CanBeNull] string comment)
9
    {
10
      return (PropertyBuilder<TProperty>) propertyBuilder.HasComment(comment);
11
    }
    也就是說我們要獲取到物體物件的注釋xml,然后讀取對應的欄位注釋,自動呼叫改方法即可,需要解決的問題大概有以下幾點,
  1. 如何獲取當前配置的欄位;
  2. 加載Xml,并根據欄位獲取對應的注釋;
  3. 如何將列舉的各項資訊都放入注釋中;

二、實作方法

    1.如何獲取當前配置的欄位

       在獲取xml的注釋中,需要的資訊有物體對應的型別以及對應的欄位,而包含這兩種型別的方法只有Property這個方法,該方法的出入參如下:           2       1
public virtual PropertyBuilder<TProperty> Property<TProperty>(
2
      [NotNull] Expression<Func<TEntity, TProperty>> propertyExpression);
            所以我們準備對這個方法進行改造,并且根據傳入的propertyExpression獲取欄位名稱,方法如下:           4       1
        public static PropertyBuilder<TProperty> SummaryProperty<TEntity, TProperty>(
2
            this EntityTypeBuilder<TEntity> entityTypeBuilder,
3
            Expression<Func<TEntity, TProperty>> propertyExpression)
4
            where TEntity : class
            根據運算式獲取欄位名稱如下:           10       1
        public static MemberInfo GetMember<T, TProperty>(this Expression<Func<T, TProperty>> expression)
2
        {
3
            MemberExpression memberExp;
4
            if (expression.Body is UnaryExpression unaryExpression)
5
                memberExp = unaryExpression.Operand as MemberExpression;
6
            else
7
                memberExp = expression.Body as MemberExpression;
8




9

            return memberExp?.Member;
10
        }
   

  2.加載Xml,并根據欄位獲取對應的注釋

    VS中的Xml格式不在此處過多解釋,屬性、方法等注釋可以根據規律去獲取,此處需要注意的是當欄位是從父類繼承而來并且父類屬于不同的dll時,需要獲取父類所在dll的xml注釋才行,另外列舉也需要同樣去處理,雖然獲取Xml資料的方法只在更新資料庫時才呼叫,但是還是需要使用字典將資料快取下來,方便下次快速獲取,具體代碼如下:           204       1
   /// <summary>
2
    /// xml注釋獲取器
3
    /// </summary>
4
    internal static class SummaryXmlCacheProvider
5
    {
6
        #region TClass
7




8

        /// <summary>
9
        /// 根據型別初始化該類所在程式集的xml
10
        /// </summary>
11
        /// <typeparam name="TClass"></typeparam>
12
        internal static void InitSummaryXml<TClass>()
13
        {
14
            var assembly = Assembly.GetAssembly(typeof(TClass));
15
            SerializeXmlFromAssembly(assembly);
16
        }
17




18

        /// <summary>
19
        /// 根據型別獲取該類所在程式集的xml
20
        /// </summary>
21
        /// <typeparam name="TClass"></typeparam>
22
        /// <returns></returns>
23
        internal static Dictionary<string, string> GetSummaryXml<TClass>()
24
        {
25
            var assembly = Assembly.GetAssembly(typeof(TClass));
26
            return SummaryCache[assembly];
27
        }
28




29

        /// <summary>
30
        /// 獲取該類在xml的key
31
        /// </summary>
32
        /// <typeparam name="TClass"></typeparam>
33
        /// <returns></returns>
34
        internal static string GetClassTypeKey<TClass>()
35
        {
36
            return TableSummaryRuleProvider.TypeSummaryKey(typeof(TClass).FullName);
37
        }
38




39

        #endregion
40




41

        #region TProperty
42




43

        /// <summary>
44
        /// 根據型別以及欄位初始化該類所在程式集的xml
45
        /// </summary>
46
        /// <typeparam name="TClass"></typeparam>
47
        /// <typeparam name="TProperty"></typeparam>
48
        /// <param name="propertyExpression"></param>
49
        internal static void InitSummaryXml<TClass, TProperty>(Expression<Func<TClass, TProperty>> propertyExpression)
50
        {
51
            var propertyAssembly = GetPropertyAssembly(propertyExpression);
52
            SerializeXmlFromAssembly(propertyAssembly);
53
        }
54




55

        /// <summary>
56
        /// 根據型別以及欄位獲取該類所在程式集的xml
57
        /// </summary>
58
        /// <typeparam name="TClass"></typeparam>
59
        /// <typeparam name="TProperty"></typeparam>
60
        /// <param name="propertyExpression"></param>
61
        /// <returns></returns>
62
        internal static Dictionary<string, string> GetSummaryXml<TClass, TProperty>(
63
            Expression<Func<TClass, TProperty>> propertyExpression)
64
        {
65
            var propertyAssembly = GetPropertyAssembly(propertyExpression);
66
            return SummaryCache[propertyAssembly];
67
        }
68




69

        /// <summary>
70
        /// 獲取該類以及欄位所在xml的key
71
        /// </summary>
72
        /// <typeparam name="TClass"></typeparam>
73
        /// <typeparam name="TProperty"></typeparam>
74
        /// <param name="propertyExpression"></param>
75
        /// <returns></returns>
76
        internal static string GetPropertyTypeKey<TClass, TProperty>(
77
            Expression<Func<TClass, TProperty>> propertyExpression)
78
        {
79
            var memberName = propertyExpression.GetMember().Name;
80
            var propertyInfo = GetPropertyInfo(propertyExpression);
81
            var propertyKey =
82
                $"{propertyInfo.DeclaringType.Namespace}.{propertyInfo.DeclaringType.Name}.{memberName}";
83
            return PropertySummaryRuleProvider.PropertyTypeSummaryKey(propertyKey);
84
        }
85




86

        #endregion
87




88

        #region TEnum
89




90

        /// <summary>
91
        /// 獲取列舉欄位的描述資訊
92
        /// </summary>
93
        /// <typeparam name="TClass"></typeparam>
94
        /// <typeparam name="TProperty"></typeparam>
95
        /// <param name="propertyExpression"></param>
96
        /// <returns></returns>
97
        internal static string GetEnumPropertyDescription<TClass, TProperty>(Expression<Func<TClass, TProperty>> propertyExpression)
98
        {
99
            var propertyInfo = GetPropertyInfo(propertyExpression);
100
            if (!propertyInfo.PropertyType.IsEnum)
101
                return string.Empty;
102
            var enumType = propertyInfo.PropertyType;
103
            SerializeXmlFromAssembly(enumType.Assembly);
104
            var propertySummaryDic = SummaryCache[enumType.Assembly];
105
            var enumNames = enumType.GetEnumNames();
106
            var enumDescDic = enumType.GetNameAndValues();
107
            var enumSummaries = new List<string>();
108
            foreach (var enumName in enumNames)
109
            {
110
                var propertyEnumKey = PropertySummaryRuleProvider.EnumTypeSummaryKey($"{enumType.FullName}.{enumName}");
111
                var enumSummary = propertySummaryDic.ContainsKey(propertyEnumKey)
112
                    ? propertySummaryDic[propertyEnumKey]
113
                    : string.Empty;
114
                var enumValue = enumDescDic[enumName];
115
                enumSummaries.Add(PropertySummaryRuleProvider.EnumTypeSummaryFormat(enumValue,enumName,enumSummary));
116
            }
117




118

            return string.Join(";", enumSummaries);
119




120

        }
121




122

        #endregion
123




124

        /// <summary>
125
        /// 根據運算式獲取屬性所在的程式集
126
        /// </summary>
127
        /// <typeparam name="TClass"></typeparam>
128
        /// <typeparam name="TProperty"></typeparam>
129
        /// <param name="propertyExpression"></param>
130
        /// <returns></returns>
131
        private static Assembly GetPropertyAssembly<TClass, TProperty>(
132
            Expression<Func<TClass, TProperty>> propertyExpression)
133
        {
134
            var propertyInfo = GetPropertyInfo(propertyExpression);
135
            var propertyAssembly = propertyInfo.Module.Assembly;
136
            return propertyAssembly;
137
        }
138




139

        /// <summary>
140
        /// 根據運算式獲取欄位屬性
141
        /// </summary>
142
        /// <typeparam name="TClass"></typeparam>
143
        /// <typeparam name="TProperty"></typeparam>
144
        /// <param name="propertyExpression"></param>
145
        /// <returns></returns>
146
        private static PropertyInfo GetPropertyInfo<TClass, TProperty>(
147
            Expression<Func<TClass, TProperty>> propertyExpression)
148
        {
149
            var entityType = typeof(TClass);
150
            var memberName = propertyExpression.GetMember().Name;
151
            var propertyInfo = entityType.GetProperty(memberName, typeof(TProperty));
152
            if (propertyInfo == null || propertyInfo.DeclaringType == null)
153
                throw new ArgumentNullException($"this property {memberName} is not belong to {entityType.Name}");
154




155

            return propertyInfo;
156
        }
157




158

        /// <summary>
159
        /// 根據程式集初始化xml
160
        /// </summary>
161
        /// <param name="assembly"></param>
162
        private static void SerializeXmlFromAssembly(Assembly assembly)
163
        {
164
            var assemblyPath = assembly.Location;
165
            var lastIndexOf = assemblyPath.LastIndexOf(".dll", StringComparison.Ordinal);
166
            var xmlPath = assemblyPath.Remove(lastIndexOf, 4) + ".xml";
167




168

            if (SummaryCache.ContainsKey(assembly))
169
                return;
170
            var xmlDic = new Dictionary<string, string>();
171
            if (!File.Exists(xmlPath))
172
            {
173
                Console.WriteLine($"未能加載xml檔案,原因:xml檔案不存在,path:{xmlPath}");
174
                SummaryCache.Add(assembly, xmlDic);
175
                return;
176
            }
177




178

            var doc = new XmlDocument();
179
            doc.Load(xmlPath);
180
            var members = doc.SelectNodes("doc/members/member");
181
            if (members == null)
182
            {
183
                Console.WriteLine($"未能加載xml檔案,原因:doc/members/member節點不存在");
184
                SummaryCache.Add(assembly, xmlDic);
185
                return;
186
            }
187




188

            foreach (XmlElement member in members)
189
            {
190
                var name = member.Attributes["name"].InnerText.Trim();
191
                if (string.IsNullOrWhiteSpace(name))
192
                    continue;
193
                xmlDic.Add(name, member.SelectSingleNode("summary")?.InnerText.Trim());
194
            }
195




196

            SummaryCache.Add(assembly, xmlDic);
197
        }
198




199

        /// <summary>
200
        /// xml注釋快取
201
        /// </summary>
202
        private static Dictionary<Assembly, Dictionary<string, string>> SummaryCache { get; } =
203
            new Dictionary<Assembly, Dictionary<string, string>>();
204
    }
   

    3.如何將列舉的各項資訊都放入注釋中

  上面的兩個步驟已經根據運算式將欄位的注釋獲取到,直接呼叫EF提供的HasComment即可,見代碼:           15       1
        public static PropertyBuilder<TProperty> SummaryProperty<TEntity, TProperty>(
2
            this EntityTypeBuilder<TEntity> entityTypeBuilder,
3
            Expression<Func<TEntity, TProperty>> propertyExpression)
4
            where TEntity : class
5
        {
6
            SummaryXmlCacheProvider.InitSummaryXml(propertyExpression);
7
            var entitySummaryDic = SummaryXmlCacheProvider.GetSummaryXml(propertyExpression);
8
            var propertyKey = SummaryXmlCacheProvider.GetPropertyTypeKey(propertyExpression);
9
            var summary = entitySummaryDic.ContainsKey(propertyKey) ? entitySummaryDic[propertyKey] : string.Empty;
10
            var enumDescription = SummaryXmlCacheProvider.GetEnumPropertyDescription(propertyExpression);
11
            summary = string.IsNullOrWhiteSpace(enumDescription) ? summary : $"{summary}:{enumDescription}";
12
            return string.IsNullOrWhiteSpace(summary)
13
                ? entityTypeBuilder.Property(propertyExpression)
14
                : entityTypeBuilder.Property(propertyExpression).HasComment(summary);
15
        }
      同時也可以設定表的注釋以及表的名稱,如下:           26       1
public static EntityTypeBuilder<TEntity> SummaryToTable<TEntity>(
2
            this EntityTypeBuilder<TEntity> entityTypeBuilder, bool hasTableComment = true,
3
            Func<string> tablePrefix = null)
4
            where TEntity : class
5
        {
6
            var tableName = GetTableName<TEntity>(tablePrefix);
7
            return hasTableComment
8
                ? entityTypeBuilder.ToTable(tableName)
9
                    .SummaryHasComment()
10
                : entityTypeBuilder.ToTable(tableName);
11
        }
12




13

        public static EntityTypeBuilder<TEntity> SummaryHasComment<TEntity>(
14
            this EntityTypeBuilder<TEntity> entityTypeBuilder) where TEntity : class
15
        {
16
            SummaryXmlCacheProvider.InitSummaryXml<TEntity>();
17
            var entityDic = SummaryXmlCacheProvider.GetSummaryXml<TEntity>();
18
            var tableKey = SummaryXmlCacheProvider.GetClassTypeKey<TEntity>();
19
            var summary = entityDic.ContainsKey(tableKey) ? entityDic[tableKey] : string.Empty;
20
            return string.IsNullOrWhiteSpace(summary) ? entityTypeBuilder : entityTypeBuilder.HasComment(summary);
21
        }
22




23

        private static string GetTableName<TEntity>(Func<string> tablePrefix)
24
        {
25
            return typeof(TEntity).Name.Replace("Entity", $"Tb{tablePrefix?.Invoke()}");
26
        }
      搞定,

三、效果展示

  運行Add-Migration InitDb即可查看生成的代碼,                       1
    public partial class InitDb : Migration
2
    {
3
        protected override void Up(MigrationBuilder migrationBuilder)
4
        {
5
            migrationBuilder.CreateTable(
6
                name: "TbGood",
7
                columns: table => new
8
                {
9
                    Id = table.Column<long>(nullable: false, comment: "主鍵")
10
                        .Annotation("SqlServer:Identity", "1, 1"),
11
                    CreateTime = table.Column<DateTime>(nullable: false, comment: "創建時間"),
12
                    CreateName = table.Column<string>(maxLength: 64, nullable: false, comment: "創建人姓名"),
13
                    UpdateTime = table.Column<DateTime>(nullable: true, comment: "更新時間"),
14
                    UpdateName = table.Column<string>(maxLength: 64, nullable: true, comment: "更新人姓名"),
15
                    Name = table.Column<string>(maxLength: 64, nullable: false, comment: "商品名稱"),
16
                    GoodType = table.Column<int>(nullable: false, comment: "物品型別:(0,Electronic) 電子產品;(1,Clothes) 衣帽服裝;(2,Food) 食品;(3,Other) 其他物品"),
17
                    Description = table.Column<string>(maxLength: 2048, nullable: true, comment: "物品描述"),
18
                    Store = table.Column<int>(nullable: false, comment: "儲存量")
19
                },
20
                constraints: table =>
21
                {
22
                    table.PrimaryKey("PK_TbGood", x => x.Id);
23
                },
24
                comment: "商品物體類");
25




26

            migrationBuilder.CreateTable(
27
                name: "TbOrder",
28
                columns: table => new
29
                {
30
                    Id = table.Column<long>(nullable: false, comment: "主鍵")
31
                        .Annotation("SqlServer:Identity", "1, 1"),
32
                    CreateTime = table.Column<DateTime>(nullable: false, comment: "創建時間"),
33
                    CreateName = table.Column<string>(maxLength: 64, nullable: false, comment: "創建人姓名"),
34
                    UpdateTime = table.Column<DateTime>(nullable: true, comment: "更新時間"),
35
                    UpdateName = table.Column<string>(maxLength: 64, nullable: true, comment: "更新人姓名"),
36
                    GoodId = table.Column<long>(nullable: false, comment: "商品Id"),
37
                    OrderStatus = table.Column<int>(nullable: false, comment: "訂單狀態:(0,Ordered) 已下單;(1,Payed) 已付款;(2,Complete) 已付款;(3,Cancel) 已取消"),
38
                    OrderTime = table.Column<DateTime>(nullable: false, comment: "下訂單時間"),
39
                    Address = table.Column<string>(maxLength: 2048, nullable: false, comment: "訂單地址"),
40
                    UserName = table.Column<string>(maxLength: 16, nullable: false, comment: "收件人姓名"),
41
                    TotalAmount = table.Column<decimal>(nullable: false, comment: "總金額")
42
                },
43
                constraints: table =>
44
                {
45
                    table.PrimaryKey("PK_TbOrder", x => x.Id);
46
                },
47
                comment: "訂單物體類");
48
        }
49




50

        protected override void Down(MigrationBuilder migrationBuilder)
51
        {
52
            migrationBuilder.DropTable(
53
                name: "TbGood");
54




55

            migrationBuilder.DropTable(
56
                name: "TbOrder");
57
        }
58
    }
   

四、寫在最后

  此種方法是在我目前能想起來比較方便生成注釋的方法了,另外還想過EntityTypeBuilder中的Property方法,最后還是放棄了,因為EntityTypeBuilder是由ModelBuilder生成,而ModelBuilder又是ModelSource中的CreateModel方法產生,最后一路深扒到DbContext中,為了搞這個注釋得不償失,最后才采取了上述的方法,若是大佬有更好的方法,恭請分享, <style>.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 { }</style> <style>.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 }</style> <style>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 }</style>

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/257294.html

標籤:Entity Framework

上一篇:2020年終總結

下一篇:2020年終總結

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more