mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
add examples domain_01
This commit is contained in:
parent
45ba67ed15
commit
f9fef12d37
21
Examples/domain_01/Domains/MusicDomain.cs
Normal file
21
Examples/domain_01/Domains/MusicDomain.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using domain_01.Entitys;
|
||||||
|
using FreeSql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace domain_01.Domains
|
||||||
|
{
|
||||||
|
public class MusicDomain
|
||||||
|
{
|
||||||
|
GuidRepository<Singer> _singerRepostiry => g.orm.GetGuidRepository<Singer>();
|
||||||
|
GuidRepository<Album> _albumRepostiry => g.orm.GetGuidRepository<Album>();
|
||||||
|
GuidRepository<Song> _songRepostiry => g.orm.GetGuidRepository<Song>();
|
||||||
|
GuidRepository<AlbumSong> _albumSongRepostiry => g.orm.GetGuidRepository<AlbumSong>();
|
||||||
|
|
||||||
|
public void SaveSong() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Examples/domain_01/Entitys/Album.cs
Normal file
21
Examples/domain_01/Entitys/Album.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace domain_01.Entitys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 专辑
|
||||||
|
/// </summary>
|
||||||
|
public class Album
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Song> Songs { get; set; }
|
||||||
|
|
||||||
|
public DateTime PublishTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
11
Examples/domain_01/Entitys/AlbumSong.cs
Normal file
11
Examples/domain_01/Entitys/AlbumSong.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace domain_01.Entitys {
|
||||||
|
public class AlbumSong {
|
||||||
|
|
||||||
|
public Guid AlbumId { get; set; }
|
||||||
|
|
||||||
|
public Guid SongId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
Examples/domain_01/Entitys/Singer.cs
Normal file
19
Examples/domain_01/Entitys/Singer.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace domain_01.Entitys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 歌手
|
||||||
|
/// </summary>
|
||||||
|
public class Singer
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public string Nickname { get; set; }
|
||||||
|
|
||||||
|
public DateTime RegTime { get; set; } = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
25
Examples/domain_01/Entitys/Song.cs
Normal file
25
Examples/domain_01/Entitys/Song.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace domain_01.Entitys {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 歌曲
|
||||||
|
/// </summary>
|
||||||
|
public class Song {
|
||||||
|
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public Guid SingerId { get; set; }
|
||||||
|
public virtual Guid Singer { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Album> Albums { get; set; }
|
||||||
|
|
||||||
|
public DateTime RegTime { get; set; } = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
23
Examples/domain_01/Program.cs
Normal file
23
Examples/domain_01/Program.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace domain_01 {
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
CreateWebHostBuilder(args).Build().Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
}
|
||||||
|
}
|
27
Examples/domain_01/Properties/launchSettings.json
Normal file
27
Examples/domain_01/Properties/launchSettings.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:54379/",
|
||||||
|
"sslPort": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repository_01": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"applicationUrl": "http://localhost:54383/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Examples/domain_01/Startup.cs
Normal file
60
Examples/domain_01/Startup.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using FreeSql;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Swashbuckle.AspNetCore.Swagger;
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace domain_01 {
|
||||||
|
public class Startup {
|
||||||
|
public Startup(IConfiguration configuration, ILoggerFactory loggerFactory) {
|
||||||
|
Configuration = configuration;
|
||||||
|
|
||||||
|
g.orm = new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Pooling=true;Max Pool Size=10")
|
||||||
|
.UseLogger(loggerFactory.CreateLogger<IFreeSql>())
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IConfiguration Configuration { get; }
|
||||||
|
|
||||||
|
public void ConfigureServices(IServiceCollection services) {
|
||||||
|
services.AddSingleton<IFreeSql>(g.orm);
|
||||||
|
|
||||||
|
services.AddMvc();
|
||||||
|
services.AddSwaggerGen(options => {
|
||||||
|
options.SwaggerDoc("v1", new Info {
|
||||||
|
Version = "v1",
|
||||||
|
Title = "FreeSql.domain_01 API"
|
||||||
|
});
|
||||||
|
//options.IncludeXmlComments(xmlPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
Console.OutputEncoding = Encoding.GetEncoding("GB2312");
|
||||||
|
Console.InputEncoding = Encoding.GetEncoding("GB2312");
|
||||||
|
|
||||||
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||||
|
loggerFactory.AddDebug();
|
||||||
|
|
||||||
|
app.UseHttpMethodOverride(new HttpMethodOverrideOptions { FormFieldName = "X-Http-Method-Override" });
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
app.UseMvc();
|
||||||
|
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c => {
|
||||||
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "FreeSql.domain_01 API V1");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class g {
|
||||||
|
public static IFreeSql orm { get; set; }
|
||||||
|
}
|
9
Examples/domain_01/appsettings.Development.json
Normal file
9
Examples/domain_01/appsettings.Development.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Debug",
|
||||||
|
"System": "Information",
|
||||||
|
"Microsoft": "Information"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
Examples/domain_01/appsettings.json
Normal file
8
Examples/domain_01/appsettings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
35
Examples/domain_01/domain_01.csproj
Normal file
35
Examples/domain_01/domain_01.csproj
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.0.1" />
|
||||||
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\FreeSql.Repository\FreeSql.Repository.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="readmeDetail.xaml.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="readmeMaster.xaml.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="readmeMenuItem.cs">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
5
Examples/domain_01/readme.md
Normal file
5
Examples/domain_01/readme.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
## 示例项目 domain_01
|
||||||
|
|
||||||
|
实体:Entitys
|
||||||
|
|
||||||
|
领域:Domains
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace repository_01.Repositorys {
|
namespace repository_01.Repositorys {
|
||||||
public class SongRepository : BaseRepository<Song, int> {
|
public class SongRepository : BaseRepository<Song, int> {
|
||||||
public SongRepository(IFreeSql fsql) : base(fsql) {
|
public SongRepository(IFreeSql fsql) : base(fsql, null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
FreeSql.sln
15
FreeSql.sln
@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Site.DAL", "Example
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Site.UI", "Examples\website\FreeSql.Site.UI\FreeSql.Site.UI.csproj", "{4F1788A6-CD82-41FE-ABFD-D14060708145}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Site.UI", "Examples\website\FreeSql.Site.UI\FreeSql.Site.UI.csproj", "{4F1788A6-CD82-41FE-ABFD-D14060708145}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain_01", "Examples\domain_01\domain_01.csproj", "{A23D0455-CA7B-442D-827E-C4C7E84F9084}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -176,6 +178,18 @@ Global
|
|||||||
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x64.Build.0 = Release|Any CPU
|
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x86.ActiveCfg = Release|Any CPU
|
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x86.Build.0 = Release|Any CPU
|
{4F1788A6-CD82-41FE-ABFD-D14060708145}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -188,6 +202,7 @@ Global
|
|||||||
{8B4A2173-E0A5-4C0C-A9E9-AE56DA11CF98} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
{8B4A2173-E0A5-4C0C-A9E9-AE56DA11CF98} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
||||||
{BA77AA20-9DDE-4C84-928C-11E3D71B3EF9} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
{BA77AA20-9DDE-4C84-928C-11E3D71B3EF9} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
||||||
{4F1788A6-CD82-41FE-ABFD-D14060708145} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
{4F1788A6-CD82-41FE-ABFD-D14060708145} = {FB34DA8D-2486-426F-B9C5-2AC88ADAF955}
|
||||||
|
{A23D0455-CA7B-442D-827E-C4C7E84F9084} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user