mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 18:48:09 +08:00
Update Demo
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,14 +22,14 @@ namespace MyTest
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Default:1
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? SchoolId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:Student Name
|
||||
/// Default:default name
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Name {get;set;}
|
||||
@@ -46,14 +46,21 @@ namespace MyTest
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public double? float {get;set;}
|
||||
public byte[] Timestamp {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public byte[] Timestamp {get;set;}
|
||||
public DateTimeOffset? Datetimeoffset {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public double? Float {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -11,8 +11,7 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<NuGetPackageImportStamp></NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -73,7 +72,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\Student.cs" />
|
||||
<Compile Include="Codes\Methods.cs" />
|
||||
<Compile Include="Models\School.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -81,9 +82,7 @@
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="x64\SQLite.Interop.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
Reference in New Issue
Block a user