diff --git a/Src/Asp.Net/SugarCodeGeneration/Codes/Methods.cs b/Src/Asp.Net/SugarCodeGeneration/Codes/Methods.cs index 690171875..859180a2e 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Codes/Methods.cs +++ b/Src/Asp.Net/SugarCodeGeneration/Codes/Methods.cs @@ -28,15 +28,29 @@ namespace SugarCodeGeneration.Codes } } - public static void AddCsproj(string fileDirectory, string projectName) + public static void AddCsproj(string classPath, string projectName) { - var files = Directory.GetFiles(fileDirectory).ToList(); + var classDirectory = Methods.GetSlnPath + "\\" +projectName+"\\"+ classPath.TrimStart('\\'); + var files = Directory.GetFiles(classDirectory).ToList().Select(it=>classPath+"\\"+Path.GetFileName(it)); var xmlPath = GetSlnPath + @"\" + projectName + @"\SugarCodeGeneration.csproj"; var xml = File.ReadAllText(xmlPath,Encoding.UTF8); var firstLine = System.IO.File.ReadLines(xmlPath, Encoding.UTF8).First(); var newXml = xml.Replace(firstLine, "").TrimStart('\r').TrimStart('\n'); - XElement xe = XElement.Parse(newXml); + XDocument xe = XDocument.Load(xmlPath); + var itemGroup=xe.Root.Elements().Where(it=>it.Name.LocalName== "ItemGroup"&&it.Elements().Any(y=>y.Name.LocalName== "Compile")).First(); + var compieList=itemGroup.Elements().ToList(); + var noAddFiles = files.Where(it => !compieList.Any(f => it.Equals(f.Attribute("Include").Value, StringComparison.CurrentCultureIgnoreCase))).ToList(); + if (noAddFiles.Any()) { + foreach (var item in noAddFiles) + { + var addItem = new XElement("Compile", new XAttribute("Include",item)); + itemGroup.AddFirst(addItem) ; + } + } + newXml = xe.ToString().Replace("xmlns=\"\"", ""); + xe = XDocument.Parse(newXml); + xe.Save(xmlPath); } } } diff --git a/Src/Asp.Net/SugarCodeGeneration/Models/Student.cs b/Src/Asp.Net/SugarCodeGeneration/Models/Student.cs index 55fb3041d..e86fd7009 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Models/Student.cs +++ b/Src/Asp.Net/SugarCodeGeneration/Models/Student.cs @@ -22,14 +22,14 @@ namespace MyTest /// /// Desc: - /// Default: + /// Default:1 /// Nullable:True /// public int? SchoolId {get;set;} /// /// Desc:Student Name - /// Default:default name + /// Default: /// Nullable:True /// public string Name {get;set;} @@ -46,14 +46,21 @@ namespace MyTest /// Default: /// Nullable:True /// - public double? float {get;set;} + public byte[] Timestamp {get;set;} /// /// Desc: /// Default: - /// Nullable:False + /// Nullable:True /// - public byte[] Timestamp {get;set;} + public DateTimeOffset? Datetimeoffset {get;set;} + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public double? Float {get;set;} } } diff --git a/Src/Asp.Net/SugarCodeGeneration/Program.cs b/Src/Asp.Net/SugarCodeGeneration/Program.cs index b81731e06..7dbc7e60e 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Program.cs +++ b/Src/Asp.Net/SugarCodeGeneration/Program.cs @@ -13,7 +13,7 @@ namespace SugarCodeGeneration { private const SqlSugar.DbType sqlServer = SqlSugar.DbType.SqlServer; private const string projectName = "SugarCodeGeneration"; - private const string classPath= projectName + @"\Models"; + private const string classPath= "Models"; private const string classNamespace = "MyTest"; private const string connectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest"; @@ -25,12 +25,12 @@ namespace SugarCodeGeneration ConnectionString = connectionString, IsAutoCloseConnection = true }); - var classDirectory = Methods.GetSlnPath +"\\"+ classPath.TrimStart('\\'); + var classDirectory = Methods.GetSlnPath +"\\"+projectName+"\\"+ classPath.TrimStart('\\'); //if all then remove .Where db.DbFirst.Where("Student","School").CreateClassFile(classDirectory, classNamespace); - //Methods.AddCsproj(classDirectory, projectName); + Methods.AddCsproj(classPath, projectName); //Generation DbContext } diff --git a/Src/Asp.Net/SugarCodeGeneration/SugarCodeGeneration.csproj b/Src/Asp.Net/SugarCodeGeneration/SugarCodeGeneration.csproj index 173cd3de0..9b9c0576d 100644 --- a/Src/Asp.Net/SugarCodeGeneration/SugarCodeGeneration.csproj +++ b/Src/Asp.Net/SugarCodeGeneration/SugarCodeGeneration.csproj @@ -11,8 +11,7 @@ v4.0 512 true - - + AnyCPU @@ -73,7 +72,9 @@ + + @@ -81,9 +82,7 @@ - - - + Always