diff --git a/test2/.vscode/launch.json b/test2/.vscode/launch.json deleted file mode 100644 index 9ba87a430c9a58f525b9fde13ab79f77394aad36..0000000000000000000000000000000000000000 --- a/test2/.vscode/launch.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net7.0/test2.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach" - } - ] -} \ No newline at end of file diff --git a/test2/.vscode/tasks.json b/test2/.vscode/tasks.json deleted file mode 100644 index d59caf35da341dc5698599870f04f801cb0d7e10..0000000000000000000000000000000000000000 --- a/test2/.vscode/tasks.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/test2.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/test2.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "--project", - "${workspaceFolder}/test2.csproj" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/test2/Models/Classes.cs b/test2/Models/Classes.cs deleted file mode 100644 index 0e59fe378b8aaa16d5b08044669ad7dea1d4a2b0..0000000000000000000000000000000000000000 --- a/test2/Models/Classes.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace test2.Models -{ - public class Classes - { - public int ClassId{get;set;} - public string? ClassName{get;set;} - } -} \ No newline at end of file diff --git a/test2/Models/StuClass.cs b/test2/Models/StuClass.cs deleted file mode 100644 index c5eee99a98f38bd3e25deef8e3689ccecf0dccae..0000000000000000000000000000000000000000 --- a/test2/Models/StuClass.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace test2.Models -{ - public class StuClass - { - public string? StuName{get;set;} - - public string? Gender{get;set;} - - public string? ClassName{get;set;} - } -} \ No newline at end of file diff --git a/test2/Models/Student.cs b/test2/Models/Student.cs deleted file mode 100644 index 4c3790a66f6f5ebc60218e0f13a5aa0f6e62cce8..0000000000000000000000000000000000000000 --- a/test2/Models/Student.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace test2.Models -{ - public class Student - { - public int StuId{get;set;} - public string? StuName{get;set;} - - public Boolean Gender{get;set;} - - public int ClassId{get;set;} - } -} \ No newline at end of file diff --git a/test2/Program.cs b/test2/Program.cs deleted file mode 100644 index d53fc66fd840440f0b18d72afd6543fc002b1977..0000000000000000000000000000000000000000 --- a/test2/Program.cs +++ /dev/null @@ -1,98 +0,0 @@ -using test2.Models; - -var rnd = new Random(1000); -var arr = Enumerable.Range(0,200).Select(_ => rnd.Next(0,10)); - -//扩展方法-> linq -var numD = arr.GroupBy(n =>n).ToDictionary(group=> group.Key, value=> value.Count()); -//查询表达式 -> linq -var res = from n in arr - group n by n into g - //既要键,又要次数 类:Student学生类(gender)(嘉远) new Student(){gender=..} - select new {g.Key,Count=g.Count()}; - -var stuList = new List(){ - new Student(){StuId=1,StuName="张三",Gender=false}, - new Student(){StuId=2,StuName="李四",Gender=true}, - new Student(){StuId=3,StuName="王五",Gender=false} -}; - -//姓名+性别 -var res1 = from stu in stuList - select new Student(){ - StuName= stu.StuName, - Gender = stu.Gender - }; - -/* foreach (var item in res1) -{ - Console.WriteLine($"{item.StuName},{item.Gender}"); -} */ - - -// -var mulArr =new int [][]{ - new int[]{1,2,3}, - new int[]{4,5,6}, - new int[]{7,8,9} -}; -//2维->转成1维 -var res2 = from arr1 in mulArr - from num in arr1 - select num; - - -var langArr = new string[]{"rust","python","java","csharp","c","golang"}; -//统计字符出现的次数 -/* var res3 = from lang in langArr - from c in lang - group c by c into g - select new{g.Key, Count = g.Count()}; */ - -//链式.Select() -var res3 = langArr.SelectMany(c=> c).GroupBy(c=>c); - -//Single,SingleOrDefault,First,Take,Skip - -/* var numList = new List{1,2,3,4,5,6,7,8,9,0}; -var res4 = numList.Skip(3).Take(3); */ - - -//连表 -var stuList1 = new List(){ - new Student(){StuId=1,StuName="张三",Gender=false,ClassId=1}, - new Student(){StuId=2,StuName="李四",Gender=true,ClassId=2}, - new Student(){StuId=3,StuName="王五",Gender=false,ClassId=1} -}; - -var clsList = new List(){ - new Classes(){ClassId=1,ClassName="1班"}, - new Classes(){ClassId=2,ClassName="2班"} -}; -/* - select * from stuList s join clsList c on s.ClassId = c.ClassId (where) - */ -var res5 = from stu in stuList1 - join cls in clsList on stu.ClassId equals cls.ClassId - select new StuClass{ - StuName = stu.StuName, - ClassName = cls.ClassName, - Gender = stu.Gender?"男":"女" - }; - -foreach (var item in res5) -{ - Console.WriteLine($"{item.StuName},{item.ClassName}"); -} - - -var numList1 =new List{1,2,3,4}; -var res6 = numList1.AsParallel().AsOrdered() -.Select(n=> { - Thread.Sleep(2000); - return n*n; -}).AsSequential(); - - - - diff --git a/test2/bin/Debug/net7.0/test2.deps.json b/test2/bin/Debug/net7.0/test2.deps.json deleted file mode 100644 index 0c425effd2619c2ba84f67c949725b044712ed63..0000000000000000000000000000000000000000 --- a/test2/bin/Debug/net7.0/test2.deps.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "runtimeTarget": { - "name": ".NETCoreApp,Version=v7.0", - "signature": "" - }, - "compilationOptions": {}, - "targets": { - ".NETCoreApp,Version=v7.0": { - "test2/1.0.0": { - "runtime": { - "test2.dll": {} - } - } - } - }, - "libraries": { - "test2/1.0.0": { - "type": "project", - "serviceable": false, - "sha512": "" - } - } -} \ No newline at end of file diff --git a/test2/bin/Debug/net7.0/test2.dll b/test2/bin/Debug/net7.0/test2.dll deleted file mode 100644 index 1b542110d30f9ed02f049624f36a8798d3faadc5..0000000000000000000000000000000000000000 Binary files a/test2/bin/Debug/net7.0/test2.dll and /dev/null differ diff --git a/test2/bin/Debug/net7.0/test2.exe b/test2/bin/Debug/net7.0/test2.exe deleted file mode 100644 index dcc4aa2caa6752c7abc8598fa83a142e3372e3da..0000000000000000000000000000000000000000 Binary files a/test2/bin/Debug/net7.0/test2.exe and /dev/null differ diff --git a/test2/bin/Debug/net7.0/test2.pdb b/test2/bin/Debug/net7.0/test2.pdb deleted file mode 100644 index 794e670111b681c8892da03c9d0fa405dbc07619..0000000000000000000000000000000000000000 Binary files a/test2/bin/Debug/net7.0/test2.pdb and /dev/null differ diff --git a/test2/bin/Debug/net7.0/test2.runtimeconfig.json b/test2/bin/Debug/net7.0/test2.runtimeconfig.json deleted file mode 100644 index 184be8b5dbee162e97a7a7bc7ca841cdc5765981..0000000000000000000000000000000000000000 --- a/test2/bin/Debug/net7.0/test2.runtimeconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "net7.0", - "framework": { - "name": "Microsoft.NETCore.App", - "version": "7.0.0" - } - } -} \ No newline at end of file diff --git a/test2/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs b/test2/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs deleted file mode 100644 index 4257f4bc63d7cf7f5e3390e9ad6d0762050449fe..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs +++ /dev/null @@ -1,4 +0,0 @@ -// -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0")] diff --git a/test2/obj/Debug/net7.0/apphost.exe b/test2/obj/Debug/net7.0/apphost.exe deleted file mode 100644 index dcc4aa2caa6752c7abc8598fa83a142e3372e3da..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/apphost.exe and /dev/null differ diff --git a/test2/obj/Debug/net7.0/ref/test2.dll b/test2/obj/Debug/net7.0/ref/test2.dll deleted file mode 100644 index ed7b0190239bfb19c74a8c20bc997ede4ee5438e..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/ref/test2.dll and /dev/null differ diff --git a/test2/obj/Debug/net7.0/refint/test2.dll b/test2/obj/Debug/net7.0/refint/test2.dll deleted file mode 100644 index ed7b0190239bfb19c74a8c20bc997ede4ee5438e..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/refint/test2.dll and /dev/null differ diff --git a/test2/obj/Debug/net7.0/test2.AssemblyInfo.cs b/test2/obj/Debug/net7.0/test2.AssemblyInfo.cs deleted file mode 100644 index 234f02e540107cf99367619fca2cfed575880dac..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -using System; -using System.Reflection; - -[assembly: System.Reflection.AssemblyCompanyAttribute("test2")] -[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] -[assembly: System.Reflection.AssemblyProductAttribute("test2")] -[assembly: System.Reflection.AssemblyTitleAttribute("test2")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] - -// 由 MSBuild WriteCodeFragment 类生成。 - diff --git a/test2/obj/Debug/net7.0/test2.AssemblyInfoInputs.cache b/test2/obj/Debug/net7.0/test2.AssemblyInfoInputs.cache deleted file mode 100644 index ef6a19f0275f204807a237e92e3bf0f22a7cb3a2..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.AssemblyInfoInputs.cache +++ /dev/null @@ -1 +0,0 @@ -5714fc67aa82e409e911f0c29729720992086520 diff --git a/test2/obj/Debug/net7.0/test2.GeneratedMSBuildEditorConfig.editorconfig b/test2/obj/Debug/net7.0/test2.GeneratedMSBuildEditorConfig.editorconfig deleted file mode 100644 index 7b3e025500bf693a8ddcb20a908f2163b49dc564..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.GeneratedMSBuildEditorConfig.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -is_global = true -build_property.TargetFramework = net7.0 -build_property.TargetPlatformMinVersion = -build_property.UsingMicrosoftNETSdkWeb = -build_property.ProjectTypeGuids = -build_property.InvariantGlobalization = -build_property.PlatformNeutralAssembly = -build_property.EnforceExtendedAnalyzerRules = -build_property._SupportedPlatformList = Linux,macOS,Windows -build_property.RootNamespace = test2 -build_property.ProjectDir = D:\WebAPI\net1班\test2\ diff --git a/test2/obj/Debug/net7.0/test2.GlobalUsings.g.cs b/test2/obj/Debug/net7.0/test2.GlobalUsings.g.cs deleted file mode 100644 index 8578f3d03de56aa5afbb2e6a3f0a9055b075f7fd..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.GlobalUsings.g.cs +++ /dev/null @@ -1,8 +0,0 @@ -// -global using global::System; -global using global::System.Collections.Generic; -global using global::System.IO; -global using global::System.Linq; -global using global::System.Net.Http; -global using global::System.Threading; -global using global::System.Threading.Tasks; diff --git a/test2/obj/Debug/net7.0/test2.assets.cache b/test2/obj/Debug/net7.0/test2.assets.cache deleted file mode 100644 index 0662181128d70303ca9aa42e26d945c2990e6895..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/test2.assets.cache and /dev/null differ diff --git a/test2/obj/Debug/net7.0/test2.csproj.AssemblyReference.cache b/test2/obj/Debug/net7.0/test2.csproj.AssemblyReference.cache deleted file mode 100644 index 606bd2948a03326744eb3572d2c0f1ac62122949..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/test2.csproj.AssemblyReference.cache and /dev/null differ diff --git a/test2/obj/Debug/net7.0/test2.csproj.CoreCompileInputs.cache b/test2/obj/Debug/net7.0/test2.csproj.CoreCompileInputs.cache deleted file mode 100644 index 5a218d16f650674cb02c2a4f9a7d45c2340827ea..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -30d3c729c2361eac884e3f9edea262993ade48b4 diff --git a/test2/obj/Debug/net7.0/test2.csproj.FileListAbsolute.txt b/test2/obj/Debug/net7.0/test2.csproj.FileListAbsolute.txt deleted file mode 100644 index 15d01f866ca8ce57caae59ef37a110204fd77842..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.csproj.FileListAbsolute.txt +++ /dev/null @@ -1,15 +0,0 @@ -D:\WebAPI\net1班\test2\bin\Debug\net7.0\test2.exe -D:\WebAPI\net1班\test2\bin\Debug\net7.0\test2.deps.json -D:\WebAPI\net1班\test2\bin\Debug\net7.0\test2.runtimeconfig.json -D:\WebAPI\net1班\test2\bin\Debug\net7.0\test2.dll -D:\WebAPI\net1班\test2\bin\Debug\net7.0\test2.pdb -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.csproj.AssemblyReference.cache -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.GeneratedMSBuildEditorConfig.editorconfig -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.AssemblyInfoInputs.cache -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.AssemblyInfo.cs -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.csproj.CoreCompileInputs.cache -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.dll -D:\WebAPI\net1班\test2\obj\Debug\net7.0\refint\test2.dll -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.pdb -D:\WebAPI\net1班\test2\obj\Debug\net7.0\test2.genruntimeconfig.cache -D:\WebAPI\net1班\test2\obj\Debug\net7.0\ref\test2.dll diff --git a/test2/obj/Debug/net7.0/test2.dll b/test2/obj/Debug/net7.0/test2.dll deleted file mode 100644 index 1b542110d30f9ed02f049624f36a8798d3faadc5..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/test2.dll and /dev/null differ diff --git a/test2/obj/Debug/net7.0/test2.genruntimeconfig.cache b/test2/obj/Debug/net7.0/test2.genruntimeconfig.cache deleted file mode 100644 index 75079fd9c23d6eb6661056cfd29d89083b763031..0000000000000000000000000000000000000000 --- a/test2/obj/Debug/net7.0/test2.genruntimeconfig.cache +++ /dev/null @@ -1 +0,0 @@ -ce35be4ab2e862ead23748caeaff73d3522518ef diff --git a/test2/obj/Debug/net7.0/test2.pdb b/test2/obj/Debug/net7.0/test2.pdb deleted file mode 100644 index 794e670111b681c8892da03c9d0fa405dbc07619..0000000000000000000000000000000000000000 Binary files a/test2/obj/Debug/net7.0/test2.pdb and /dev/null differ diff --git a/test2/obj/project.assets.json b/test2/obj/project.assets.json deleted file mode 100644 index a4971c75ddb55508d18de46f7054df3bba677bb3..0000000000000000000000000000000000000000 --- a/test2/obj/project.assets.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "version": 3, - "targets": { - "net7.0": {} - }, - "libraries": {}, - "projectFileDependencyGroups": { - "net7.0": [] - }, - "packageFolders": { - "C:\\Users\\Administrator\\.nuget\\packages\\": {} - }, - "project": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "D:\\WebAPI\\net1班\\test2\\test2.csproj", - "projectName": "test2", - "projectPath": "D:\\WebAPI\\net1班\\test2\\test2.csproj", - "packagesPath": "C:\\Users\\Administrator\\.nuget\\packages\\", - "outputPath": "D:\\WebAPI\\net1班\\test2\\obj\\", - "projectStyle": "PackageReference", - "configFilePaths": [ - "C:\\Users\\Administrator\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "net7.0" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.102\\RuntimeIdentifierGraph.json" - } - } - } -} \ No newline at end of file diff --git a/test2/obj/project.nuget.cache b/test2/obj/project.nuget.cache deleted file mode 100644 index 5db50e33457ea96642e5e8d45caa47be311560c6..0000000000000000000000000000000000000000 --- a/test2/obj/project.nuget.cache +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 2, - "dgSpecHash": "/IXdOmBcFp8tRzIcqu2+wXniyWjCLZq1P75JK3wqky/odsIUOdzvnRJG7/9YgyLUhFA6iLz5H7RZRPZCDqqF8A==", - "success": true, - "projectFilePath": "D:\\WebAPI\\net1班\\test2\\test2.csproj", - "expectedPackageFiles": [], - "logs": [] -} \ No newline at end of file diff --git a/test2/obj/test2.csproj.nuget.dgspec.json b/test2/obj/test2.csproj.nuget.dgspec.json deleted file mode 100644 index f5e3b2393b3abce20116383e3b9b0bb989742aba..0000000000000000000000000000000000000000 --- a/test2/obj/test2.csproj.nuget.dgspec.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "format": 1, - "restore": { - "D:\\WebAPI\\net1班\\test2\\test2.csproj": {} - }, - "projects": { - "D:\\WebAPI\\net1班\\test2\\test2.csproj": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "D:\\WebAPI\\net1班\\test2\\test2.csproj", - "projectName": "test2", - "projectPath": "D:\\WebAPI\\net1班\\test2\\test2.csproj", - "packagesPath": "C:\\Users\\Administrator\\.nuget\\packages\\", - "outputPath": "D:\\WebAPI\\net1班\\test2\\obj\\", - "projectStyle": "PackageReference", - "configFilePaths": [ - "C:\\Users\\Administrator\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "net7.0" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.102\\RuntimeIdentifierGraph.json" - } - } - } - } -} \ No newline at end of file diff --git a/test2/obj/test2.csproj.nuget.g.props b/test2/obj/test2.csproj.nuget.g.props deleted file mode 100644 index 3c0382201f50fa8a7c74bb5c728e3f5c249ef706..0000000000000000000000000000000000000000 --- a/test2/obj/test2.csproj.nuget.g.props +++ /dev/null @@ -1,15 +0,0 @@ - - - - True - NuGet - $(MSBuildThisFileDirectory)project.assets.json - $(UserProfile)\.nuget\packages\ - C:\Users\Administrator\.nuget\packages\ - PackageReference - 6.4.0 - - - - - \ No newline at end of file diff --git a/test2/obj/test2.csproj.nuget.g.targets b/test2/obj/test2.csproj.nuget.g.targets deleted file mode 100644 index 3dc06ef3cc4057524bf5d2cd49936dff789cebe8..0000000000000000000000000000000000000000 --- a/test2/obj/test2.csproj.nuget.g.targets +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/test2/test2.csproj b/test2/test2.csproj deleted file mode 100644 index f02677bf640fc66fa042fa584e1b3dcda56f300b..0000000000000000000000000000000000000000 --- a/test2/test2.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - diff --git a/testProgram/.vscode/launch.json b/testProgram/.vscode/launch.json deleted file mode 100644 index 820631b2b8ad1f471e73e1490962f497021891a0..0000000000000000000000000000000000000000 --- a/testProgram/.vscode/launch.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net7.0/testProgram.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach" - } - ] -} \ No newline at end of file diff --git a/testProgram/.vscode/tasks.json b/testProgram/.vscode/tasks.json deleted file mode 100644 index 30e9795ccdc6b0a5f51e06966acb2448b4570d6e..0000000000000000000000000000000000000000 --- a/testProgram/.vscode/tasks.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/testProgram.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/testProgram.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "--project", - "${workspaceFolder}/testProgram.csproj" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/testProgram/Program.cs b/testProgram/Program.cs deleted file mode 100644 index 8d431673cbbfcaee66d464f4acffa1de213b182b..0000000000000000000000000000000000000000 --- a/testProgram/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* 练习1 */ - -/* -var lst = new List{1,2,3,40,5,6,7,8,9}; - List result = new List(); //lst.Count -for (int i = 0; i < lst.Count; i++) -{ - if(lst[i] > 3 && lst[i] % 2 == 0){ - result.Add(lst[i]); - } -} -result.Sort(); -for (int i = 0; i < result.Count; i++) -{ - Console.Write($"{result[i]} > "); -} */ - - - -//linq(语言集成查询); -//linq:查询表达式(伪SQL语句), 链式(扩展方法); - - - -//T-SQL: select * from lst where [lst[i] > 3 && lst[i] % 2 == 0] orderby (条件); -//1.查询表达式 ,特点:以select,groupby结尾, -/* var res = from n in lst - where n>3 && n%2==0 - orderby n - select n; */ - -//2.链式表达式 MVC -//var res1 = lst.Where(n=> n>3 && n%2==0).OrderBy(n => n).Select(n=>n); - - -//linq特性:延迟性,惰性(defer), 消耗性(exhaust) -//常用的方法:Where()/Select()/OrderBy()/GroupBy()/Single()/First(); diff --git a/testProgram/README.md b/testProgram/README.md deleted file mode 100644 index c6abb74d7ac3883c7ddcc104cb4cc66e04da2023..0000000000000000000000000000000000000000 --- a/testProgram/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# WebAPI - -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/testProgram/bin/Debug/net7.0/testProgram.deps.json b/testProgram/bin/Debug/net7.0/testProgram.deps.json deleted file mode 100644 index de88afb8979667d16df248468c01e4fa9b8ebca2..0000000000000000000000000000000000000000 --- a/testProgram/bin/Debug/net7.0/testProgram.deps.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "runtimeTarget": { - "name": ".NETCoreApp,Version=v7.0", - "signature": "" - }, - "compilationOptions": {}, - "targets": { - ".NETCoreApp,Version=v7.0": { - "testProgram/1.0.0": { - "runtime": { - "testProgram.dll": {} - } - } - } - }, - "libraries": { - "testProgram/1.0.0": { - "type": "project", - "serviceable": false, - "sha512": "" - } - } -} \ No newline at end of file diff --git a/testProgram/bin/Debug/net7.0/testProgram.dll b/testProgram/bin/Debug/net7.0/testProgram.dll deleted file mode 100644 index 7ad0ca27de2c00e3d685507d04a4a86ec7a30145..0000000000000000000000000000000000000000 Binary files a/testProgram/bin/Debug/net7.0/testProgram.dll and /dev/null differ diff --git a/testProgram/bin/Debug/net7.0/testProgram.exe b/testProgram/bin/Debug/net7.0/testProgram.exe deleted file mode 100644 index ceaef107d6418041f84662cb841f580030b9a9d0..0000000000000000000000000000000000000000 Binary files a/testProgram/bin/Debug/net7.0/testProgram.exe and /dev/null differ diff --git a/testProgram/bin/Debug/net7.0/testProgram.pdb b/testProgram/bin/Debug/net7.0/testProgram.pdb deleted file mode 100644 index b96b764a5d1b460055641aba993abc8263288abf..0000000000000000000000000000000000000000 Binary files a/testProgram/bin/Debug/net7.0/testProgram.pdb and /dev/null differ diff --git a/testProgram/bin/Debug/net7.0/testProgram.runtimeconfig.json b/testProgram/bin/Debug/net7.0/testProgram.runtimeconfig.json deleted file mode 100644 index 184be8b5dbee162e97a7a7bc7ca841cdc5765981..0000000000000000000000000000000000000000 --- a/testProgram/bin/Debug/net7.0/testProgram.runtimeconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "net7.0", - "framework": { - "name": "Microsoft.NETCore.App", - "version": "7.0.0" - } - } -} \ No newline at end of file diff --git a/testProgram/course.md b/testProgram/course.md deleted file mode 100644 index f66d58d9fc9f7e77dc06bfeca50dc6064580d8bd..0000000000000000000000000000000000000000 --- a/testProgram/course.md +++ /dev/null @@ -1,28 +0,0 @@ - -//c#: 隐式声明变量var, lambda:表达式(箭头函数) , linq() -//集合 增删改查(linq:语言集成查询) -//创建一个list集合 -/* List lst = new List(); -List lst1 = new List(100); */ -var lst = new List{1,2,3,4,5}; - -var arr = new int[5]{6,7,8,9,0}; -//添加:末尾添加 -//lst.Add(6); -lst.AddRange(arr); - -//插入insert(),insertRange() - -//删除remove 清空:clear - - -//改 lst[index] = target -// Console.WriteLine(lst[0]); - - - -//遍历集合 -foreach (var item in lst) -{ - Console.Write($"{item} "); -} diff --git a/testProgram/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs b/testProgram/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs deleted file mode 100644 index 4257f4bc63d7cf7f5e3390e9ad6d0762050449fe..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs +++ /dev/null @@ -1,4 +0,0 @@ -// -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0")] diff --git a/testProgram/obj/Debug/net7.0/apphost.exe b/testProgram/obj/Debug/net7.0/apphost.exe deleted file mode 100644 index ceaef107d6418041f84662cb841f580030b9a9d0..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/apphost.exe and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/ref/testProgram.dll b/testProgram/obj/Debug/net7.0/ref/testProgram.dll deleted file mode 100644 index 9d197c05565deffc8e4783e5020b72d93652d8d9..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/ref/testProgram.dll and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/refint/testProgram.dll b/testProgram/obj/Debug/net7.0/refint/testProgram.dll deleted file mode 100644 index 9d197c05565deffc8e4783e5020b72d93652d8d9..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/refint/testProgram.dll and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfo.cs b/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfo.cs deleted file mode 100644 index 5ba2c979e1ecf631303919c83a12af237deff30f..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -using System; -using System.Reflection; - -[assembly: System.Reflection.AssemblyCompanyAttribute("testProgram")] -[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] -[assembly: System.Reflection.AssemblyProductAttribute("testProgram")] -[assembly: System.Reflection.AssemblyTitleAttribute("testProgram")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] - -// 由 MSBuild WriteCodeFragment 类生成。 - diff --git a/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfoInputs.cache b/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfoInputs.cache deleted file mode 100644 index af937ddd53b52099185dad67380428583fff0832..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.AssemblyInfoInputs.cache +++ /dev/null @@ -1 +0,0 @@ -5457ff18b395e8d8eda0e55937af45c06e300e9f diff --git a/testProgram/obj/Debug/net7.0/testProgram.GeneratedMSBuildEditorConfig.editorconfig b/testProgram/obj/Debug/net7.0/testProgram.GeneratedMSBuildEditorConfig.editorconfig deleted file mode 100644 index bfd417ca8f7c9d859071619a4c0764857a9a430a..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.GeneratedMSBuildEditorConfig.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -is_global = true -build_property.TargetFramework = net7.0 -build_property.TargetPlatformMinVersion = -build_property.UsingMicrosoftNETSdkWeb = -build_property.ProjectTypeGuids = -build_property.InvariantGlobalization = -build_property.PlatformNeutralAssembly = -build_property.EnforceExtendedAnalyzerRules = -build_property._SupportedPlatformList = Linux,macOS,Windows -build_property.RootNamespace = testProgram -build_property.ProjectDir = d:\WebAPI\net1班\testProgram\ diff --git a/testProgram/obj/Debug/net7.0/testProgram.GlobalUsings.g.cs b/testProgram/obj/Debug/net7.0/testProgram.GlobalUsings.g.cs deleted file mode 100644 index 8578f3d03de56aa5afbb2e6a3f0a9055b075f7fd..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.GlobalUsings.g.cs +++ /dev/null @@ -1,8 +0,0 @@ -// -global using global::System; -global using global::System.Collections.Generic; -global using global::System.IO; -global using global::System.Linq; -global using global::System.Net.Http; -global using global::System.Threading; -global using global::System.Threading.Tasks; diff --git a/testProgram/obj/Debug/net7.0/testProgram.assets.cache b/testProgram/obj/Debug/net7.0/testProgram.assets.cache deleted file mode 100644 index 8b13aa4ac171e30ec426fc8773d47c728a5a1e4a..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/testProgram.assets.cache and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/testProgram.csproj.AssemblyReference.cache b/testProgram/obj/Debug/net7.0/testProgram.csproj.AssemblyReference.cache deleted file mode 100644 index 606bd2948a03326744eb3572d2c0f1ac62122949..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/testProgram.csproj.AssemblyReference.cache and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/testProgram.csproj.CoreCompileInputs.cache b/testProgram/obj/Debug/net7.0/testProgram.csproj.CoreCompileInputs.cache deleted file mode 100644 index 7a715365bbceb16351855a7c068185d3e2840a9e..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -7582d2cdae3fa2828bc2d20ee5ea54e53d66001f diff --git a/testProgram/obj/Debug/net7.0/testProgram.csproj.FileListAbsolute.txt b/testProgram/obj/Debug/net7.0/testProgram.csproj.FileListAbsolute.txt deleted file mode 100644 index 936afa0f20aff29e708097655676fdb2f1c2a271..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.csproj.FileListAbsolute.txt +++ /dev/null @@ -1,15 +0,0 @@ -D:\WebAPI\net1班\testProgram\bin\Debug\net7.0\testProgram.exe -D:\WebAPI\net1班\testProgram\bin\Debug\net7.0\testProgram.deps.json -D:\WebAPI\net1班\testProgram\bin\Debug\net7.0\testProgram.runtimeconfig.json -D:\WebAPI\net1班\testProgram\bin\Debug\net7.0\testProgram.dll -D:\WebAPI\net1班\testProgram\bin\Debug\net7.0\testProgram.pdb -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.csproj.AssemblyReference.cache -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.GeneratedMSBuildEditorConfig.editorconfig -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.AssemblyInfoInputs.cache -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.AssemblyInfo.cs -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.csproj.CoreCompileInputs.cache -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.dll -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\refint\testProgram.dll -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.pdb -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\testProgram.genruntimeconfig.cache -D:\WebAPI\net1班\testProgram\obj\Debug\net7.0\ref\testProgram.dll diff --git a/testProgram/obj/Debug/net7.0/testProgram.dll b/testProgram/obj/Debug/net7.0/testProgram.dll deleted file mode 100644 index 7ad0ca27de2c00e3d685507d04a4a86ec7a30145..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/testProgram.dll and /dev/null differ diff --git a/testProgram/obj/Debug/net7.0/testProgram.genruntimeconfig.cache b/testProgram/obj/Debug/net7.0/testProgram.genruntimeconfig.cache deleted file mode 100644 index 02542c0297ab3b1e2768dfb620299b2e3436da47..0000000000000000000000000000000000000000 --- a/testProgram/obj/Debug/net7.0/testProgram.genruntimeconfig.cache +++ /dev/null @@ -1 +0,0 @@ -a6fafc7332fdf19e8d9511052dd9f68d63c32b57 diff --git a/testProgram/obj/Debug/net7.0/testProgram.pdb b/testProgram/obj/Debug/net7.0/testProgram.pdb deleted file mode 100644 index b96b764a5d1b460055641aba993abc8263288abf..0000000000000000000000000000000000000000 Binary files a/testProgram/obj/Debug/net7.0/testProgram.pdb and /dev/null differ diff --git a/testProgram/obj/project.assets.json b/testProgram/obj/project.assets.json deleted file mode 100644 index 526f75baefe156250a7652d5132e7afda98db135..0000000000000000000000000000000000000000 --- a/testProgram/obj/project.assets.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "version": 3, - "targets": { - "net7.0": {} - }, - "libraries": {}, - "projectFileDependencyGroups": { - "net7.0": [] - }, - "packageFolders": { - "C:\\Users\\Administrator\\.nuget\\packages\\": {} - }, - "project": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj", - "projectName": "testProgram", - "projectPath": "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj", - "packagesPath": "C:\\Users\\Administrator\\.nuget\\packages\\", - "outputPath": "D:\\WebAPI\\net1班\\testProgram\\obj\\", - "projectStyle": "PackageReference", - "configFilePaths": [ - "C:\\Users\\Administrator\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "net7.0" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.102\\RuntimeIdentifierGraph.json" - } - } - } -} \ No newline at end of file diff --git a/testProgram/obj/project.nuget.cache b/testProgram/obj/project.nuget.cache deleted file mode 100644 index 4f60c43b59c40b392d9c999a34dbca3b4f2945f4..0000000000000000000000000000000000000000 --- a/testProgram/obj/project.nuget.cache +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 2, - "dgSpecHash": "9bU5Xii3OhFGtLOR9p5ZIHZxdyMs9Px7brr35mczl7aPMczMgfYEU2se1fjkjrjfpj3h2wWpnPavnAcAKSLeqA==", - "success": true, - "projectFilePath": "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj", - "expectedPackageFiles": [], - "logs": [] -} \ No newline at end of file diff --git a/testProgram/obj/testProgram.csproj.nuget.dgspec.json b/testProgram/obj/testProgram.csproj.nuget.dgspec.json deleted file mode 100644 index f9e25f9b7636acc35813b789bb9f1b3e37d5ee6c..0000000000000000000000000000000000000000 --- a/testProgram/obj/testProgram.csproj.nuget.dgspec.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "format": 1, - "restore": { - "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj": {} - }, - "projects": { - "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj": { - "version": "1.0.0", - "restore": { - "projectUniqueName": "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj", - "projectName": "testProgram", - "projectPath": "D:\\WebAPI\\net1班\\testProgram\\testProgram.csproj", - "packagesPath": "C:\\Users\\Administrator\\.nuget\\packages\\", - "outputPath": "D:\\WebAPI\\net1班\\testProgram\\obj\\", - "projectStyle": "PackageReference", - "configFilePaths": [ - "C:\\Users\\Administrator\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" - ], - "originalTargetFrameworks": [ - "net7.0" - ], - "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, - "https://api.nuget.org/v3/index.json": {} - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "projectReferences": {} - } - }, - "warningProperties": { - "warnAsError": [ - "NU1605" - ] - } - }, - "frameworks": { - "net7.0": { - "targetAlias": "net7.0", - "imports": [ - "net461", - "net462", - "net47", - "net471", - "net472", - "net48", - "net481" - ], - "assetTargetFallback": true, - "warn": true, - "frameworkReferences": { - "Microsoft.NETCore.App": { - "privateAssets": "all" - } - }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.102\\RuntimeIdentifierGraph.json" - } - } - } - } -} \ No newline at end of file diff --git a/testProgram/obj/testProgram.csproj.nuget.g.props b/testProgram/obj/testProgram.csproj.nuget.g.props deleted file mode 100644 index 3c0382201f50fa8a7c74bb5c728e3f5c249ef706..0000000000000000000000000000000000000000 --- a/testProgram/obj/testProgram.csproj.nuget.g.props +++ /dev/null @@ -1,15 +0,0 @@ - - - - True - NuGet - $(MSBuildThisFileDirectory)project.assets.json - $(UserProfile)\.nuget\packages\ - C:\Users\Administrator\.nuget\packages\ - PackageReference - 6.4.0 - - - - - \ No newline at end of file diff --git a/testProgram/obj/testProgram.csproj.nuget.g.targets b/testProgram/obj/testProgram.csproj.nuget.g.targets deleted file mode 100644 index 3dc06ef3cc4057524bf5d2cd49936dff789cebe8..0000000000000000000000000000000000000000 --- a/testProgram/obj/testProgram.csproj.nuget.g.targets +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/testProgram/test.cs b/testProgram/test.cs deleted file mode 100644 index a00650e3fef10c977326ba50d14640f34e5e4fba..0000000000000000000000000000000000000000 --- a/testProgram/test.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace testProgram -{ - public class test - { - - } -} \ No newline at end of file diff --git a/testProgram/test.js b/testProgram/test.js deleted file mode 100644 index 9bc85bb14144a03bbddfbc23f38bd42bb5860223..0000000000000000000000000000000000000000 --- a/testProgram/test.js +++ /dev/null @@ -1 +0,0 @@ -new Promise() \ No newline at end of file diff --git a/testProgram/testProgram.csproj b/testProgram/testProgram.csproj deleted file mode 100644 index f02677bf640fc66fa042fa584e1b3dcda56f300b..0000000000000000000000000000000000000000 --- a/testProgram/testProgram.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net7.0 - enable - enable - - - diff --git "a/\346\235\216\350\210\222/.keep" "b/\346\235\216\350\210\222/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\346\235\216\350\210\222/2023-05-22.md" "b/\346\235\216\350\210\222/2023-05-22.md" new file mode 100644 index 0000000000000000000000000000000000000000..ad179dec9656213cece254521eed9463b9b94d06 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-22.md" @@ -0,0 +1,43 @@ +~~~markdown +## 2023-05-22笔记 +1. 集合/linq + webAPI +2. uniapp + docker 微服务 +3. JS语言(弱类型语言 vue node,js):var a = 5 a="5" const arr=[1,2,3] 增删改查 +4. dot NET(C#,强类型,Java,C++):var a =5; a一直整形,只能通过强转 +5. 数组(较原始的集合):int[]arr = new int[5] 改,查 +6. 集合collection(装的都是同类型的元素):增删改查 + +#### linq:语言集成查询; +```cs +List oo = new List{1,2,3,4,5,6,7,8,9,0}; +List result = new List(); //oo.count +for (int i =0;i 3 && oo[i] % 2 == 0){ + result.Ass(oo[i]); + } +} +result.Sort(); +for(int i =0;i 3 && oo[i] % 2 == 0] order by (条件); + +1. 查询表达式,特点:以select ,groupby结尾, +```cs +var res = from n in lst + where n > 3 && n % 2 == 0 + order by n + select n; +``` +2. 链式表达式 MVC +var res1 = lst.Where(n=> n>3 && n%2 ==0).OrderBy(n => n).Select(n=>n); + +var rnd = new Random(1000); +var arr = Enumerable.Range(0,100).Select(_ => rnd.Next(0,10)); + +//linq特性:延迟性(derfer),消耗性(exhaust) +//常用的方法:Where()/Select()/OrderBy()/GroupBy()/Single()/First() +~~~ \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-23.md" "b/\346\235\216\350\210\222/2023-05-23.md" new file mode 100644 index 0000000000000000000000000000000000000000..4fc33e68001f1dc62ff2195145852d0b24d8df2b --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-23.md" @@ -0,0 +1,57 @@ +##2023-05-23 + +# C# 枚举(Enum) + +枚举是一组命名整型常量。枚举类型是使用 **enum** 关键字声明的。 + +C# 枚举是值类型。换句话说,枚举包含自己的值,且不能继承或传递继承。 + +## 声明 *enum* 变量 + +声明枚举的一般语法: + +``` +enum +{ + enumeration list +}; +``` + +其中, + +- *enum_name* 指定枚举的类型名称。 +- *enumeration list* 是一个用逗号分隔的标识符列表。 + +枚举列表中的每个符号代表一个整数值,一个比它前面的符号大的整数值。默认情况下,第一个枚举符号的值是 0.例如: + +``` +enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat }; +``` + +## 实例 + +下面的实例演示了枚举变量的用法: + +## 实例 + +**using** System; + +**public** **class** EnumTest +{ + **enum** Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; + + **static** **void** Main() + { + **int** x = (**int**)Day.Sun; + **int** y = (**int**)Day.Fri; + Console.WriteLine("Sun = {0}", x); + Console.WriteLine("Fri = {0}", y); + } +} + +当上面的代码被编译和执行时,它会产生下列结果: + +```markdown +Sun = 0 +Fri = 5 +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-24.md" "b/\346\235\216\350\210\222/2023-05-24.md" new file mode 100644 index 0000000000000000000000000000000000000000..1eeb4b9f5d05df7e157d87c85fc411767eb64e98 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-24.md" @@ -0,0 +1,51 @@ +# webapi入门 +## 创建项目 +dotnet new webapi -o 项目名称 +## 跨越 +```c# +//依赖关系注入 +builder.Services.AddCors(c=>c.AddPolicy("any",p=>p.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())); + +//注册 +app.UseCors("any"); +``` +```html +`` + +``` +## newc# +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace bbb.Controllers +{ + [ApiController] + [Route("api/[controller]/[action]")] + public class NewApiController : ControllerBase + { + + [HttpGet] + public string Get(string name) + { + return $"{name},你好"; + } + + [HttpGet] + public string Get1() + { + return "不太好"; + } + } +} +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-25.md" "b/\346\235\216\350\210\222/2023-05-25.md" new file mode 100644 index 0000000000000000000000000000000000000000..7c1e7a1c9a3209d8716a235423040c8690b312ff --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-25.md" @@ -0,0 +1,80 @@ +# promise +## promise异步用法 +```js +const promise = new Promise((resolve, reject) => { + // 异步操作 + setTimeout(() => { + if (Math.random() < 0.5) { + resolve('success'); + } else { + reject('error'); + } + }, 1000); +}); + +promise.then(result => { + console.log(result); +}).catch(error => { + console.log(error); +}); +``` +## Promise 函数 +```js +function print(delay, message) { + return new Promise(function (resolve, reject) { + setTimeout(function () { + console.log(message); + resolve(); + }, delay); + }); +} + +print(1000, "First").then(function () { + return print(4000, "Second"); +}).then(function () { + print(3000, "Third"); +}); +``` +## 练习 +```js +'use strict' +console.log("1.使用promise,在页面输入两个数字,3秒后弹出结果。"); +/* +首先,我们创建了一个 Promise 对象。在 Promise 构造函数中,使用 jq 方法获取前端用户输入的两个数字,利用Number方式转换数据类型 +并使用 setTimeout 方法模拟一个异步操作,即等待 3 秒后返回两个数字的和。 +然后,我们使用 then 方法来监听 Promise 对象的状态,并在 Promise 对象的状态变为 resolved(完成)时弹出结果,即两个数字的和。 +*/ +//绑定事件触发 +function getAll() { + //// 创建 Promise 对象 + let promise = new Promise((resolve,reject)=>{ + let a = new Number($('[name=a]').val()); + let b = new Number($('[name=b]').val()); + // let a = parseInt(document.getElementsByName("a")[0].value); + // let b = parseInt(document.getElementsByName("b")[0].value); + console.log(a,b); + // 模拟异步操作,3秒后返回结果 + setTimeout(()=>{ + let num = a+b; + resolve(num); + },3000); + }) + // 使用 Promise 对象 + promise.then((result)=>{ + alert(`两个数字的和为${result}`) + }) +} +``` +# axios跨域请求 +## axios +Axios 是一个基于 promise 网络请求库,作用于node.js 和浏览器中。 它是 isomorphic 的(即同一套代码可以运行在浏览器和node.js中)。在服务端它使用原生 node.js http 模块, 而在客户端 (浏览端) 则使用 XMLHttpRequests。 +## 安装 +### 使用 npm或者yarn: +``` +npm install axios +yarn add axios +``` +### 使用 jsDelivr CDN: +``` + +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-26.md" "b/\346\235\216\350\210\222/2023-05-26.md" new file mode 100644 index 0000000000000000000000000000000000000000..a1440c5cd8f5784dc2087e08aa92e6c77986c89f --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-26.md" @@ -0,0 +1,133 @@ +# webapi +## 创建不要https的文件 +``` +dotnet new webapi -o 名称 --no-https +``` +## 创建解决方案 +``` +dotnet new sln -n 名称 +``` +安装solution插件 + +## 传参get +```c# +namespace webapi0526.Controllers +{ + [ApiController] + [Route("api/[controller]/[action]")] + public class NewWebAPI : ControllerBase + { + [HttpGet("{name}")]//传参 + public string Get(string name){ + return $"{name}"; + } + [HttpGet("{name}/{id}")]//多个传参 + public string Get1(string name,string id){ + return $"{name}---{id}"; + } + } +} +``` + +## 练习post +### 前端html js +```html +
+ + + + + + + + + + + + + +
用户名:
密码:
+
+ + + + +``` +### 后端model +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace webapi0526.Models +{ + + public class AccountModels + { + public string ? Account{get;set;} + public string Pwd{get;set;} + } +} +``` +### controllers +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Cors; +using webapi0526.Models; + +namespace webapi0526.Controllers +{ + [ApiController] + [Route("api/[controller]/[action]")] + public class NewWebAPI : ControllerBase + { + [HttpGet("{name}")]//传参 + public string Get(string name) + { + return $"{name}"; + } + [HttpGet("{name}/{id}")]//多个传参 + public string Get1(string name, string id) + { + return $"{name}---{id}"; + } + [HttpPost]//添加用户信息 /user/id + [EnableCors("any")] + public string Post(AccountModels model) + { + return $"{model.Account}-{model.Pwd}"; + } + [HttpPut]//更新用户信息 /user/id + public string Put() + { + return "put"; + } + [HttpDelete]//删除用户信息 /user/id + public string Delete() + { + return "delete"; + } + } +} +``` +### axios跨域 +```c# +builder.Services.AddCors(c=>c.AddPolicy("any",p=>p.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())); +app.UseCors("any"); +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-29.md" "b/\346\235\216\350\210\222/2023-05-29.md" new file mode 100644 index 0000000000000000000000000000000000000000..35b74ff1e9fc53f9fbe80d0a1e526639b0324b73 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-29.md" @@ -0,0 +1,8 @@ +## asp.net core创建Webapi + +API |描述 |请求正文 |响应正文 +1. GET /api/todoitems|获取所有待办事项|None|待办事项的数组 +2. GET /api/todoitems/{id}|按ID获取项|None|待办事项 +3. POST /api/todoitems|添加新项|待办事项|待办事项 +4. PUT /api/todoitems/{id}|更新现有项|待办事项|None +5. DELETE /api/todoitems/{id}|删除项|无|None \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-30.md" "b/\346\235\216\350\210\222/2023-05-30.md" new file mode 100644 index 0000000000000000000000000000000000000000..f38179dcc17f7d5e44cc3ef41dbb08742e9ac5dc --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-30.md" @@ -0,0 +1,42 @@ +## ORM框架 +### EF Core 可以帮助我们更加方便、快捷地与数据库进行交互。 +1. 打开控制台并键入以下命令: +```c# +dotnet add package Microsoft.EntityFrameworkCore +dotnet add package Microsoft.EntityFrameworkCore.SqlServer +dotnet add package Microsoft.EntityFrameworkCore.Design +``` + +2. 安装工具包 +```c# +dotnet tool install -g dotnet-ef +``` +3. 连接数据库 +```c# +dotnet ef Dbcontext scaffold "Server=CODER-QURSCPGAM\SQLEXPRESS;uid=sa;pwd=123456;Database=OrerderInfo TrustServerCertificate=True" -o Entities Microsoft.EntityFrameworkCore.sqlserver +``` + + +```C# + + + [HttpGet] + //查询所有药品 + public IActionResult Get() + { + var context = new OrderInfoContext(); + var res = context.OrderInfos.Select(o => o); + return Ok(res); + } + [HttpGet("{statee}")] + //查询已配送的订单 + public IActionResult Get1(int statee) + { + var context = new OrderInfoContext(); + var res1 = context.OrderInfos.Where(o=>o.State==statee); + return Ok(res1); + } + + + +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-05-31.md" "b/\346\235\216\350\210\222/2023-05-31.md" new file mode 100644 index 0000000000000000000000000000000000000000..4572784af7849f7035c3e929e79afe29d14e81c5 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-05-31.md" @@ -0,0 +1,35 @@ +### 创建迁移数据库 +```c# +dotnet ef migrations add InitialCreate +dotnet ef database update +``` +### 数据注释 +在类里面表的id,Entity+id为默认主键 +如何设置主键在属性上面加一个[key] + +### 导航属性 +更新到数据库时 +它自己可以创建外键 + +### 数据连接String +可以放到APPsetting.json里封装 + +然后在Program连接上下文 + +```c# +{ + "ConnectionStrings": { + "Default" : "Server=.;database=CarsInfo;uid=sa;pwd=123456;TrustServerCertificate=True" + }, +} +var configuration = builder.Configuration; + +//上下文 +builder.Services.AddDbContext(options=>{ + var res = configuration.GetConnectionString("Default"); //res:配置字符串 + Console.WriteLine(res); + options.UseSqlServer(configuration.GetConnectionString("Default")); +}); + +``` + \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-01.md" "b/\346\235\216\350\210\222/2023-06-01.md" new file mode 100644 index 0000000000000000000000000000000000000000..7966b9e9fbbede1176aec98ba86d1948bfd07a8d --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-01.md" @@ -0,0 +1,32 @@ +1. 数据注释网址 +```c# +https://learn.microsoft.com/zh-cn/ef/ef6/modeling/code-first/data-annotations + +fluent API:https://learn.microsoft.com/zh-cn/ef/ef6/modeling/code-first/fluent/relationships +``` +2. 上下文注册 +```c# +AddDbContext<>() +``` +3. 全局取消追踪 +```c# +QueryTrackngBehavior(QTB.NoTracking) +``` +4. 连接配置 +```c# +appsettings.json +``` +5. EFCore里的数据校验特性 +```c# +[Required] [MinLength(3,ErrorMessage = "名称长度至少为3")] [Display(Name = "名称")] public string Name { get; set; } +``` +6. 数据种子 +```c# +数据种子就是表的初始数据初始数据 +``` +7. Tips +```c# +ErrorMsg是校验失败时显示的提示信息。 + +EFCore里的数据校验特性主要来源于System.ComponentModel.DataAnnotations命名空间 +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-02.md" "b/\346\235\216\350\210\222/2023-06-02.md" new file mode 100644 index 0000000000000000000000000000000000000000..772e2bdb8a4a6b69f0baf29ba6c18ad7a34d613b --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-02.md" @@ -0,0 +1,122 @@ +**终端建vue**: + +npx create-vue Front ;路由vue router要yes 启动:npx vite + +## 给views添加文件: +Carsview(可以用钩子函数比较方便),添加ajax ,npm i axios,添加跨域 + +### 配置路由: + +```js +{ path:'/cars', + name:'cars', + component:()=>import('@/views/Cars/CarsView.vue')} +``` + + + +### hooks中的carshooks.js: + +```js +import { ref } from 'vue' +import { getCarsInfo,deleteCar } from '@/api/cars' + +//hooks:钩子函数(自定义) use+... +export const useCars = () => { const carList = ref(null); + + const _getCarsInfo = () => {getCarsInfo().then(res => {carList.value = res;})} + + const DeleteCarById = (id)=>{deleteCar(id); } + + _getCarsInfo(); + return {carList,DeleteCarById}} +``` + +### Cars的CarsView: + +```vue +##### + + +``` + +### 再建立一个uitls:http.js创建axios实例: + +```js +import axios from 'axios'; + +const http = axios.create({ + baseURL:"http://localhost:5064/WeatherForecast", + timeout:3000 +}); + +export default http; +``` + +### 建立api文件cars.js: + +```js +import http from '@/uitls/http'; + +//获取所有车列表 +export const getCarsInfo = async () => { + return await http.get('/Cars').then(res=>res.data); +} +//根据id删除车 +export const deleteCar = async (id)=>{ + return await http.delete(`/Cars/${id}`).then(res=>{ + console.log(res); + }) +} +``` + +//按需导出+》获取所有车列表 + +getCarsInfo=async()=>{await http.get('.Cars').then(res=>res.data);} + + + +```cs +// Add services to the container. 跨域问题 Program: +builder.Services.AddCors(c=> c.AddPolicy("any",p=>p.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod())); + +//创建连接,controllers: +[HttpGet] + public IActionResult Cars() + { + var res = _context.Cars.Include(c => c.OwnnerModel).Select(c => new + { + CardId = c.CarId, + CarOwnner = c.OwnnerModel.OwnnerName, + CarName = c.CarName, + CarType = c.CarType, + }).ToList(); + + if (res != null) + { + return Ok(res); + }; + return NotFound(); + } + + +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-05.md" "b/\346\235\216\350\210\222/2023-06-05.md" new file mode 100644 index 0000000000000000000000000000000000000000..4d1c14430b31026cbb59c23cb908d4e8b57e448b --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-05.md" @@ -0,0 +1,51 @@ +# Dependency Injection +## DI +DI: 依赖注入Dependency Injection,是实现IoC的一个手段,方法 + + +1. 使用接口或基类将依赖关系实现抽象化。 +2. 在服务容器中注册依赖关系。 .NET 提供了一个内置的(IoC Containner)服务容器 IServiceProvider。 服务通常在应用启动时注册,并追加到 IServiceCollection。 添加所有服务后,可以使用 BuildServiceProvider 创建服务容器。 +3. 将服务注入到使用它的类的构造函数中。 框架负责创建依赖关系的实例,并在不再需要时将其释放。 + + +The type of the service to add.添加到服务的类型 +## 示例 +### controllers +```c# +using Microsoft.AspNetCore.Mvc; +using _0605webi.Services; +namespace _0605webi.Controllers; + +[ApiController] +[Route("[controller]/[action]")] +public class WeatherForecastController : ControllerBase +{ + private readonly MILKTea mt; + + public WeatherForecastController(MILKTea mILKTea){ + this.mt = mILKTea; + } + + + [HttpGet] + public string get(){ + // var tea = new MILKTea(); + return mt.getTea(); + } +} + +``` +### services +```c# +namespace _0605webi.Services; + +public class MILKTea{ + public string getTea(){ + return "古茗买一送一"; + } +} +``` +### program.cs +```c# +builder.Services.AddTransient(); +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-06.md" "b/\346\235\216\350\210\222/2023-06-06.md" new file mode 100644 index 0000000000000000000000000000000000000000..c8a591366560727f2fe32c600415664622dec75d --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-06.md" @@ -0,0 +1,98 @@ +# DI详解和三种服务生命周期 +## DI详解 +依赖注入 +1. +IoC:控制反转 +DI:依赖关系注入 +IoC容器:服务收集器 + +依赖倒置 +```c# +using _0606web.Services; +using _0606web.Services.IServices; +using Microsoft.AspNetCore.Mvc; +namespace _0606web.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private readonly IMilkTea mt; + + public WeatherForecastController(IMilkTea mILKTea){ + this.mt = mILKTea; + } + + + [HttpGet] + public string get(){ + // var tea = new MILKTea(); + return mt.getTea(); + } +} +``` +```c# +namespace _0606web.Services.IServices +{ + public interface IMilkTea + { + string getTea(); + } +} +``` +```c# +using _0606web.Services.IServices; + +namespace _0606web.Services +{ + public class MilkTea : IMilkTea + { + public MilkTea(Tea tea) + { + + } + public string getTea(){ + return "古茗+1"; + } + } +} +``` +```c# +//注册:瞬态AddSingleton,AddScoped +// builder.Services.AddTransient(); +// builder.Services.AddTransient(); +// builder.Services.AddTransient(); + +//:<服务类型(一般是一个接口),(实现该接口的类)> +builder.Services.AddTransient(); +// builder.Services.AddTransient(); +// builder.Services.AddTransient(); +``` + +## 三种服务生命周期 +```c# +builder.Services.AddScoped(typeof(IA),typeof(A)); +builder.Services.AddTransient(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(typeof(IA),typeof(A)); +//singleton +builder.Services.AddSingleton(new A("什么")); +``` +``` +AddSingleton:单例 :从头到尾只有一个对象 只new一下 +AddScope:作用域(线程单例) : 发起请求的时候,会实例化 +Addtransient:瞬态 每一次注入,都会进行new实例化 +``` +``` + test1第1次 test2第2次 发起请求第3次 4 +Singleton √ +Scoped √ √ +Transient √ √ √ √ +``` +AddDbContext():默认是一个scoped, + +### 应用场景: + +Singleton 账号(缓存)redis + +作用域:缓存(前面一个实例需要传输数据给后面一个实例) diff --git "a/\346\235\216\350\210\222/2023-06-07.md" "b/\346\235\216\350\210\222/2023-06-07.md" new file mode 100644 index 0000000000000000000000000000000000000000..ba41bc6b8e886596262638715fd2ebffca3ddd97 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-07.md" @@ -0,0 +1,61 @@ +# 什么是日志 +Web API 日志是记录 Web API 请求和响应信息的一种记录形式。通常,在开发和运维过程中,我们都需要对 Web API 进行日志记录以便跟踪和分析问题。Web API 日志通常包括以下信息: + +1. 请求信息:包括请求 URL、请求方法(GET、POST等)、请求头、请求参数等。 +2. 响应信息:包括响应状态码、响应头、响应体等。 +3. 异常信息:记录请求或响应中出现的异常信息。 +4. 访问来源:记录请求的来源 IP、User-Agent 等信息。 +5. 时间戳:记录日志生成的时间。 + +通过对 Web API 日志进行分析,可以帮助我们快速定位问题所在,提高系统的可靠性和稳定性。 +# Serilog +Serilog 是一个强大的 .NET 日志库,它提供了许多灵活的配置选项和扩展机制,可以帮助开发人员轻松地记录和处理日志信息。下面是使用 Serilog 记录 Web API 日志的基本步骤: + +1. 安装 Serilog 库:在 Visual Studio 中,可以使用 dotnet 包管理器安装 Serilog 和 Serilog.Sinks.Console、Serilog.Sinks.File 等扩展库。具体命令如下: + +``` +dotnet add package Serilog +dotnet add package Serilog.Sinks.Console +dotnet add package Serilog.Sinks.File +``` + +2. 配置 Serilog:在 Web API 项目的 Program.cs 文件中添加以下代码: + +```c# +using Serilog; +using Serilog.Events; + +//writeTo:日志输出到哪,Console,File +//outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}" +var logger = new LoggerConfiguration() + // .MinimumLevel.Information() + // .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .WriteTo.Console() + .WriteTo.File( + "Logs/logs.txt", + restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, + //TimeStamp:时间戳 yyyy-MM-dd HH:mm:ss.fff + //Level:输出的格式u:upper转为大写 3:只要三个字符 + //Message:lj : 左对齐 + //NewLine:日志换行 + //Exception:记录错误 + outputTemplate: "[{Timestamp: yyyy-MM-dd HH:mm:ss.fff} {Level:u3}] {Message:lj} {Properties:j} {NewLine} {Exception}") + .Enrich.FromLogContext() //追踪日志性能较好 + .CreateLogger(); + + logger.Information("项目启动"); + + + var builder = WebApplication.CreateBuilder(args); + + + //清除内置的日志记录 + builder.Logging.ClearProviders(); + + builder.Logging.AddSerilog(logger); + +``` + + + +通过以上步骤,就完成了使用 Serilog 记录 Web API 日志的基本操作。当然,Serilog 的配置及使用方法非常丰富,开发人员可以根据实际需要进行更加详细的配置和扩展。 \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-08.md" "b/\346\235\216\350\210\222/2023-06-08.md" new file mode 100644 index 0000000000000000000000000000000000000000..cb5fd37fa86b50cab790b7599afc342b3e843fa9 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-08.md" @@ -0,0 +1,187 @@ +# serilog日志存入数据库 +## 安装依赖 +1. 安装serilog: +``` +dotnet add package serilog.AspNetCore, +dotnet add package serilog.AspNet.Core.Settings, +dotnet add package Serilog.Settings.AppSettings +``` +链接数据库 +``` +dotnet add package serilog.sinks.mssqlserver +``` +## 链接数据库配置 +在appsetting.json里面配置 +```json +{ + "ConnectionStrings": { + "SerilogConnection":"Server=.;uid=sa;pwd=123456;Database=logDB;TrustServercertificate=true" + }, + + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": { + "Default": "Information" + }, + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/webapi-.log", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Username} {Message:lj}{Exception}{NewLine}" + } + }, + { + "Name":"Console" + } + ] + } +} +``` +## 配置serilog +在program.cs里面写入 +```c# +using Serilog; +using Serilog.Sinks.MSSqlServer; + +// Log.Logger = new LoggerConfiguration() +// .ReadFrom +// .AppSettings() +// .CreateLogger(); + + +// Log.Logger = new LoggerConfiguration() +// .MinimumLevel.Information() +// .WriteTo.Console() +// .WriteTo.File( +// "Lofs/log-.log", +// rollingInterval:RollingInterval.Day //文件名已有:追加日志记录 没有文件名,重新创建文件 +// ) +// .CreateLogger(); + + + + +var builder = WebApplication.CreateBuilder(args); + +// var sinkopt = new MSSqlServerSinkOptions{ +// TableName="MyLog", +// AutoCreateSqlDatabase=true, +// AutoCreateSqlTable=true +// }; +var sinkopt = new MSSqlServerSinkOptions(); +sinkopt.TableName="MyLog"; +sinkopt.AutoCreateSqlDatabase=true; +sinkopt.AutoCreateSqlTable=true; +var columnopt = new ColumnOptions(); +columnopt.Store.Remove(StandardColumn.Properties); +columnopt.Store.Add(StandardColumn.LogEvent); + +var config = builder.Configuration; +Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .WriteTo.MSSqlServer( + connectionString:builder.Configuration.GetConnectionString("SerilogConnection") , + // connectionString: "Server=.;uid=sa;pwd=123456;Database=logDB;TrustServercertificate=true", + sinkOptions:sinkopt, + columnOptions:columnopt + ) + // .ReadFrom.Configuration(config) + .CreateLogger(); + + +var test = new {Class = 1, Name="希儿"}; +var arr = new string[2]{"克拉拉","白露"}; +Log.Information("{@test},{$arr}",test,arr); + +//清除内置的日志记录 +builder.Logging.ClearProviders(); +builder.Host.UseSerilog(); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + + +app.UseSerilogRequestLogging(); + + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); + +``` +## WeatherForecast.cs +```cs +namespace _0608serilog; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} + +``` + +## WeatherForecastController.cs +``` +using Microsoft.AspNetCore.Mvc; + +namespace _0608serilog.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} + +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-09.md" "b/\346\235\216\350\210\222/2023-06-09.md" new file mode 100644 index 0000000000000000000000000000000000000000..726b474782fe6d22d1d6c07f4613c4b6cfc2e8dd --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-09.md" @@ -0,0 +1,115 @@ +# 什么是appsettings +appsettings指的是应用程序的配置文件,它可以包含应用程序中所需的各种设置。在ASP.NET Core应用程序中,通常会使用appsettings.json作为配置文件,该文件位于项目的根目录下。 + +appsettings.json文件采用JSON格式存储数据,它可以包含多个不同环境(例如:Development、Staging、Production)下的配置信息。通过ASP.NET Core的环境变量和LaunchSettings配置,我们可以指定当前应用程序所处的环境。 + +在应用程序启动时,ASP.NET Core会读取appsettings.json文件,并将其中的配置信息封装到一个Options对象中,然后注册到应用程序的服务容器中。如果需要使用这些配置信息,只需要在需要的地方通过依赖注入的方式获取Options对象即可。 + +当然,在ASP.NET Core中还有一些其他的配置方式,例如:命令行参数、环境变量、XML配置文件等。在实际应用程序开发中,我们可以根据具体的需求选择合适的配置方式。 + + +# appsettings的使用方法 +在ASP.NET Core应用程序中,我们可以使用以下步骤来使用appsettings配置文件: + +1. 创建appsettings.json文件,该文件通常位于项目的根目录下。在该文件中,可以定义应用程序所需的各种配置信息。 + +例如,下面是一个示例的appsettings.json文件: + +```json +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=MyDatabase;Trusted_Connection=True;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} +``` + +2. 在应用程序启动时,读取appsettings.json配置文件,并将配置信息封装到Options对象中。 + +在ASP.NET Core应用程序中,我们可以使用IConfiguration接口来读取appsettings.json配置文件的内容。通过依赖注入的方式,我们可以将这个IConfiguration对象注册到应用程序的服务容器中,然后就可以在需要使用配置信息的地方获取它。 + +例如,在Startup.cs文件中的ConfigureServices方法中,可以使用如下代码来注册IConfiguration对象: + +```csharp +public void ConfigureServices(IServiceCollection services) +{ + IConfiguration configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build(); + + services.AddSingleton(configuration); +} +``` + +3. 在需要使用配置信息的地方,通过依赖注入的方式获取Options对象,并从中读取所需的配置信息。 + +例如,在控制器中,可以通过构造函数注入一个Options对象,然后就可以从中读取配置信息: + +```csharp +public class MyController : Controller +{ + private readonly IConfiguration _configuration; + + public MyController(IConfiguration configuration) + { + _configuration = configuration; + } + + public IActionResult Index() + { + string connectionString = _configuration.GetConnectionString("DefaultConnection"); + LogLevel logLevel = _configuration.GetValue("Logging:LogLevel:Default"); + + // ... + } +} +``` + +在上面的示例代码中,我们通过GetConnectionString方法和GetValue方法从Options对象中读取了配置信息。其中,GetConnectionString方法用于获取连接字符串,GetValue方法用于获取日志级别等其他配置信息。 + +总之,通过使用appsettings配置文件,我们可以很方便地管理应用程序的各种配置信息,让应用程序变得更加灵活和可扩展。 + +# 什么是ActionFilter + ActionFilter 是一个 ASP.NET MVC 中的过滤器,它可以在动作方法执行前或执行后进行一些操作。可以使用 ActionFilter 来实现一些常见的功能,比如日志记录、授权、异常处理等等。为了使用 ActionFilter,需要创建一个继承自 ActionFilterAttribute 的类,然后在控制器或者动作方法中使用该特性来应用这个过滤器。ActionFilter 提供了四个方法可以重写:OnActionExecuting、OnActionExecuted、OnResultExecuting 和 OnResultExecuted。这些方法分别在动作方法执行前、执行后、视图结果执行前和执行后触发,可以通过重写这些方法来实现自定义的业务逻辑。 + +# ActionFilter的使用 + 要使用 ActionFilter,需要遵循以下步骤: + +1. 创建一个继承自 ActionFilterAttribute 的类,并重写 OnActionExecuting、OnActionExecuted、OnResultExecuting 和 OnResultExecuted 方法中的一个或多个方法。这些方法将提供您想要实现的自定义逻辑。 + +2. 在控制器类或具体的动作方法上使用 [YourCustomActionFilter] 特性来应用该过滤器。如果您希望在整个控制器类上应用该过滤器,则可以将特性应用到控制器类上,否则可以将其应用到您想要过滤的特定动作方法上。 + +例如,以下是一个简单的 ActionFilter 类的示例: + +```csharp +public class MyActionFilterAttribute : ActionFilterAttribute +{ + public override void OnActionExecuted(ActionExecutedContext filterContext) + { + // 实现您的业务逻辑 + base.OnActionExecuted(filterContext); + } +} +``` + +然后可以将该过滤器应用到控制器类或某个具体的动作方法上,例如: + +```csharp +[MyActionFilter] +public class HomeController : Controller +{ + public ActionResult Index() + { + return View(); + } +} +``` + +这样,在 Index 动作方法执行前或执行后,就会触发 MyActionFilter 中的 OnActionExecuting 或 OnActionExecuted 方法,从而执行您实现的自定义逻辑。 \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-12.md" "b/\346\235\216\350\210\222/2023-06-12.md" new file mode 100644 index 0000000000000000000000000000000000000000..f351b14d204228c83dce93bf614b444fb1f2cbf1 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-12.md" @@ -0,0 +1,80 @@ +1. 创建三个项目 `Entity` 、`WebAPI` 和 `EFCore` +```PowerShell +dotnet new webapi -o WebAPI --no-https +dootnet new classlib Entity +dootnet new classlib EFCore +``` + +2. 在 Entity 中添加几个类 +```c# +using System.Text.Json.Serialization; + +namespace Entity +{ + public class Food + { + public int Id { get; set; } + public string FoodName { get; set; } = null!; + public string TypeId { get; set; } = null!; + public bool DeleteState { get; set; } + + [JsonIgnore] + public FoodType? FoodType { get; set; } + } +} +``` + +```c# +namespace Entity +{ + public class FoodType + { + public int Id { get; set; } + public string TypeName { get; set; } = null!; + public bool DeleteState { get; set; } + public List Foods { get; set; } + } +} +``` + +3. 在 EFCore 项目中添加类 +```C# +using Entity; +using Microsoft.EntityFrameworkCore; + + +namespace EFCore.Context +{ + public class FoodContext : DbContext + { + public FoodContext(DbContextOptions options) : base(options) { } + + public DbSet Foods { get; set; } + public DbSet FoodTypes { get; set; } + } +} +``` + +4. 在 WebAPI 项目中的 appsettings.json 中添加代码 +```json + "ConnectionStrings": { + "Default": "Server=DESKTOP-G7633NQ;uid=sa;pwd=123456;Database=Blog;TrustServerCertificate = true" + }, +``` + + +5. 在 WeiAPI 项目中的 program.cs 中添加代码 +```C# +builder.Services.AddDbContext(options => +{ + options.UseSqlServer(builder.Configuration.GetConnectionString("Default")); + + options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); +}); +``` + +6. 在 EFCore 中生成迁移文件 +```PowerShell +dotnet ef migrations add init --startup-project ..\WebAPI\ +dotnet ef database update --startup-project ..\WebAPI +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-13.md" "b/\346\235\216\350\210\222/2023-06-13.md" new file mode 100644 index 0000000000000000000000000000000000000000..8f068c1ede989621efddef7cf458867a06c6f2a7 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-13.md" @@ -0,0 +1,256 @@ +1. 新建四个个项目 +```PowerShell +dotnet new classlib -o IRepository +dotnet new classlib -o Repository +dotnet new classlib -o IService +dotnet new classlib -o Service +``` + +2. 在 IRepository 项目中添加几个接口 +基础接口, 写了一些接口通用的方法 +```C# +using System.Linq.Expressions; + +namespace IRepository +{ + public interface IBaseRepository where TEntity : class, new() + { + // 添加单条数据 + public Task CreateAsync(TEntity entity); + + // 删除 + public Task DeleteAsync(TEntity entity); + + // 修改 + public Task UpdateAsync(TEntity entity); + + // 根据id查找数据 + public Task FindByIdAsync(int id); + + // 根据单个条件查找数据 + public Task FindOneAsync(Expression> exp); + + public Task> FindByManyAsync(Expression> exp); + + public Task> FindAllAsync(); + } +} +``` + +```C# +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRepository +{ + public interface IFoodRepository : IBaseRepository + { + + } +} +``` + +```C# +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRepository +{ + public interface IFoodTypeRepository:IBaseRepository + { + + } +} +``` + +3. 在 Repository 项目中添加几个类 +基础类, 写了项目中类的一些通用方法 +```C# +using EFCore.Context; +using IRepository; +using Microsoft.EntityFrameworkCore; +using System.Linq.Expressions; + +namespace Repository +{ + public abstract class BaseRepository : IBaseRepository where TEntity : class,new() + { + protected FoodContext foodContext; + public virtual async Task CreateAsync(TEntity entity) + { + await foodContext.Set().AddAsync(entity); + + return await foodContext.SaveChangesAsync() > 0; + } + + public virtual async Task DeleteAsync(TEntity entity) + { + return await UpdateAsync(entity); + } + + public virtual async Task> FindAllAsync() + { + return await foodContext.Set().ToListAsync(); + } + + public virtual async Task FindByIdAsync(int id) + { + return await foodContext.Set().FindAsync(id); + } + + public virtual async Task> FindByManyAsync(Expression> exp) + { + return await foodContext.Set().Where(exp).ToListAsync(); + } + + public virtual async Task FindOneAsync(Expression> exp) + { + return await foodContext.Set().FirstOrDefaultAsync(exp); + } + + public virtual async Task UpdateAsync(TEntity entity) + { + foodContext.Set().Update(entity); + + return await foodContext.SaveChangesAsync() > 0; + } + } +} +``` + +```C# +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IRepository; +using EFCore.Context; +using Microsoft.EntityFrameworkCore; +using System.Linq.Expressions; + +namespace Repository +{ + public class FoodRepository : BaseRepository, IFoodRepository + { + private readonly FoodContext _foodContext; + + public FoodRepository(FoodContext foodContext) + { + base.foodContext = foodContext; + _foodContext = foodContext; + } + + public override async Task> FindAllAsync() + { + return await _foodContext.Foods.Include(x=>x.FoodType).ToListAsync(); + } + + public override async Task> FindByManyAsync(Expression> exp) + { + return await _foodContext.Foods.Include(x=>x.FoodType).Where(exp).ToListAsync(); + } + + public override async Task FindByIdAsync(int id) + { + return await _foodContext.Foods.Include(x => x.FoodType).FirstOrDefaultAsync(x=>x.Id == id); + } + + public override async Task FindOneAsync(Expression> exp) + { + return await _foodContext.Foods.Include(x => x.FoodType).FirstOrDefaultAsync(exp); + } + } +} +``` + +```C# +using Entity; +using IRepository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Repository +{ + public class FoodTypeRepository : BaseRepository, IFoodTypeRepository + { + + } +} +``` + +4. 在 IService 项目中添加接口 +```C# +using System.Linq.Expressions; + +namespace IService +{ + public interface IBaseService where TEntity : class,new() + { + // 添加单条数据 + public Task CreateAsync(TEntity entity); + + // 删除 + public Task DeleteAsync(TEntity entity); + + // 修改 + public Task UpdateAsync(TEntity entity); + + // 根据id查找数据 + public Task FindByIdAsync(int id); + + // 根据单个条件查找数据 + public Task FindOneAsync(Expression> exp); + + public Task> FindByManyAsync(Expression> exp); + + public Task> FindAllAsync(); + } +} +``` + +```C# +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IService +{ + public interface IFoodService : IBaseService + { + + } +} +``` + +```C# +using Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IService +{ + public interface IFoodTypeService : IBaseService + { + + } +} +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-14.md" "b/\346\235\216\350\210\222/2023-06-14.md" new file mode 100644 index 0000000000000000000000000000000000000000..f1a98e9f18b15d5d761a703b20ff36abf4f3b728 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-14.md" @@ -0,0 +1,106 @@ +1. 在 WeiAPI 项目中的 program.cs 中添加代码来注册依赖项 +```C# +builder.Services.AddScoped, FoodService>(); +builder.Services.AddScoped, FoodTypeService>(); +builder.Services.AddScoped, FoodRepository>(); +builder.Services.AddScoped, FoodTypeRepository>(); +``` + +2. 创建一个类库用于规范控制器返回数据 +```PowerShell +dotnet new classlib -o Util +``` + +3. 在 Util 项目中添加类 +```C# +namespace Utils +{ + public class ApiReturnHelper + { + public static ApiReturn Succeed(dynamic data) + { + return new ApiReturn() + { + Code = 200, + Message = "OK", + Data = data + }; + } + + public static ApiReturn Failed() + { + return new ApiReturn() + { + Code = 500, + }; + } + } +} +``` + +```C# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Utils +{ + public record ApiReturn + { + public int Code { get; set; } + public string Message { get; set; } + public dynamic Data { get; set; } + } +} +``` + + +4. 在 WeiAPI 项目中添加一个控制器 +```C# +using EFCore.Context; +using Entity; +using IService; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Utils; + +namespace WebAPI.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class FoodController : ControllerBase + { + private readonly IBaseService _service; + + public FoodController(IBaseService service) + { + _service = service; + } + + [HttpGet("foods")] + public async Task> GetAllFoods() + { + var result = await _service.FindAllAsync(); + + if(result != null && result.Count == 0) + { + return ApiReturnHelper.Failed(); + } + + return ApiReturnHelper.Succeed(result); + } + } +} +``` + + +## 注意 +1. 在上面第三步中出现的 `dynamic` 关键字: + - `dynamic` 是一种类型,它允许在运行时动态地处理对象的类型和成员。 + - 使用 dynamic 关键字声明的变量可以存储任何类型的值,并且可以像任何其他对象一样进行操作,而无需在编译时指定其具体类型。 + +2. `record` 关键字 + - `record` 是一种引用类型(class)的声明方式,用于定义不可变的数据结构. `record` 类型的实例是值类型,它们的值在创建后不能更改 \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-15.md" "b/\346\235\216\350\210\222/2023-06-15.md" new file mode 100644 index 0000000000000000000000000000000000000000..aebc5c7699d20d33e3b0975f79d1960bb5402bfe --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-15.md" @@ -0,0 +1,98 @@ +1. 在 Entity 项目中安装 Identity +```PowerShell +dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore +``` + +2. 在 Entity 项目中新建类 User 、 Role (这里修改的是 Identity 自带的表) +```C# +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class User :IdentityUser + { + public bool DeleteState { get; set; } + } +} +``` + +```C# +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Role : IdentityRole + { + + } +} +``` + + +3. 在 EFCore 项目的 FoodContext.cs 文件修改 +```C# +using Entity; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + + +namespace EFCore.Context +{ + public class FoodContext : IdentityDbContext// <> 里面是修改的表, 最后一个是类型 + { + public FoodContext(DbContextOptions options) : base(options) { } + + public DbSet Foods { get; set; } + public DbSet FoodTypes { get; set; } + + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.Property(x=>x.DeleteState).HasDefaultValue(false); + }); + + modelBuilder.Entity(entity => + { + entity.Property(x => x.DeleteState).HasDefaultValue(false); + }); + + // 过滤器 + modelBuilder.Entity(option => option.HasQueryFilter(x => !x.DeleteState)); + modelBuilder.Entity(option => option.HasQueryFilter(x => !x.DeleteState)); + + modelBuilder.Entity>().HasNoKey(); + modelBuilder.Entity>().HasNoKey(); + modelBuilder.Entity>().HasNoKey(); + } + } +} +``` + + +4. 在 WeiAPI 项目中的 program.cs 中添加代码来注册依赖项 +```C# +builder.Services.AddScoped, UserService>(); +builder.Services.AddScoped, UserRepository>(); + +builder.Services.AddIdentity() + .AddEntityFrameworkStores();// 指定使用哪个上下文 +``` + +5. 生成迁移文件 +```PowerShell +dotnet ef migrations add init --startup-project ..\WebAPI\ +dotnet ef database update --startup-project ..\WebAPI\ +``` \ No newline at end of file diff --git "a/\346\235\216\350\210\222/2023-06-16.md" "b/\346\235\216\350\210\222/2023-06-16.md" new file mode 100644 index 0000000000000000000000000000000000000000..9031270f697ab8cc18472c31053cf0c5d8e8bcf8 --- /dev/null +++ "b/\346\235\216\350\210\222/2023-06-16.md" @@ -0,0 +1,75 @@ +# 什么是Dto +1.用途: 用于进行数据传输,不包含任何统业务逻辑。 + +2.数据粒度:DTO 通常以较大的粒度表示数据,可携带多个相关属性和对象。dto的目标是传递批量数据,以减少网络开销和提高性能 + +3.可变性:可以根据需要修改其属性值。这样方便将从数据库从一个地方传输到另一个地方,或进行数据转换和映射 + +4.关注点:dto关注数据的传输。 + +5.dto:通常不依赖与业务逻辑,可以认为是无状态的。 + +# autoMapper 自动关系映射。 (除了jsonIgnore的另一种) +是一个用于对象映射的开源库。 +## 1.添加依赖 +下载自动映射依赖包 +dotnet add package AutoMapper.Extensions.Microsoft.DependencyInjection --version 7.0.0 +## 2.创建返回dto类 +```C# +public class UserDto + { + public Guid id { get; set; } + + public string name { get; set; } + + public List ArticleName { get; set; }=new List(); + } + +``` +## 3.创建映射工具类 +```C# +public class DTOMapper: Profile + { + //在构造函数中创建映射关系 + public DTOMapper() { + //forMember 表示要为类里边的哪一个字段进行映射 ,一对多 这里的articleName 是UserDto里的表示需要把映射的结果给这个字段 + base.CreateMap().ForMember(x => x.ArticleName, opt => + { //这里的src表示 user 通过其中的 article表然后指定其title字段进行映射 + opt.MapFrom(src => src.ariticle.Select(x => x.Title)); + }).ForMember(x => x.name, opt => + { + opt.MapFrom(src => src.UserName); + }); + + } + + } +``` +## 4.在控制器中使用 +```C# + IUserService _userService; + private IMapper _mapper; + + public apiUserController(IUserService userService,IMapper mapper) + { + this._userService= userService; + this._mapper = mapper; + } + + [HttpGet("getUserAll")] + public async Task> GetUserAll() + { + var res =await _userService.getIncludeUserAsync(); + if(res != null) + { + //将查询出来的结果进行转换然后返回 + var resultUserDto=_mapper.Map>(res); + return ApiReturnsHelper.Success(resultUserDto); + } + else + { + return ApiReturnsHelper.fail("Failed"); + } + } + +``` \ No newline at end of file