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

相关文章
相关标签/搜索