ABP學習之旅

一、我使用ABP的啓動模板(http://www.aspnetboilerplate.com/Templates)來建立一個Web應用程序。數據庫

二、加載項目解決方案json

  在abp根據模板建立解決方案後,編譯報錯,提示某個包的版本不對。
  解決方案:https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.jsonapi

  

三、在.Core中建立entity工具

  生成poco實體類的工具:EntityFramework Reverse POCO Generator,能夠根據數據庫生成具備DataAnnotations的實體類:
  能夠經過vs的擴展安裝,也能夠經過這個地址:https://marketplace.visualstudio.com/items?itemName=SimonHughes.EntityFrameworkReversePOCOGenerator#qna
  生成DataAnnotations特性,須要在T4中作以下設置更改:this

  • Settings.ConnectionStringName = "Test"; // Searches for this connection string in config files listed below in the ConfigFilenameSearchOrder setting
  • Settings.UseDataAnnotations = true; // If true, will add data annotations to the poco classes.
  • Settings.UseDataAnnotationsSchema = true; // UseDataAnnotations must also be true. If true, will add data annotations schema to the poco classes.
  • 在dataAnnotation上加長字段長度,針對char和varcahr:
      if (Settings.UseDataAnnotations)
        {
            if(c.Ordinal > 1 && !commentWritten)
                WriteLine(string.Empty);    // Leave a blank line before the next property

            foreach (var dataAnnotation in c.DataAnnotations)
            {        
                //將char、varchar的dataAnnotation上加上長度,如varchar(10),以兼容.net core
                if(dataAnnotation.ToString().StartsWith("Column"))
                {                    
                    if(dataAnnotation.ToString().Contains("varchar"))
                        WriteLine("        [" + dataAnnotation.ToString().Replace("varchar","varchar("+c.MaxLength+")") + "]");
                    else if(dataAnnotation.ToString().Contains("char"))
                        WriteLine("        [" + dataAnnotation.ToString().Replace("char","char("+c.MaxLength+")")+ "]");
                }
                else
                {
                    WriteLine("        [" + dataAnnotation + "]");
                }

            }
        }

四、方法EntityFramworkCore的DBContext增長DBSetspa

======================================.net

Add-Migration "Initial"get

update-databasestring

======================================it

相關文章
相關標籤/搜索