From f9fef12d374706c949ccb6f77331b3826c99d716 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Tue, 5 Mar 2019 18:16:25 +0800 Subject: [PATCH] add examples domain_01 --- Examples/domain_01/Domains/MusicDomain.cs | 21 +++++++ Examples/domain_01/Entitys/Album.cs | 21 +++++++ Examples/domain_01/Entitys/AlbumSong.cs | 11 ++++ Examples/domain_01/Entitys/Singer.cs | 19 ++++++ Examples/domain_01/Entitys/Song.cs | 25 ++++++++ Examples/domain_01/Program.cs | 23 +++++++ .../domain_01/Properties/launchSettings.json | 27 +++++++++ Examples/domain_01/Startup.cs | 60 +++++++++++++++++++ .../domain_01/appsettings.Development.json | 9 +++ Examples/domain_01/appsettings.json | 8 +++ Examples/domain_01/domain_01.csproj | 35 +++++++++++ Examples/domain_01/readme.md | 5 ++ .../Repositorys/SongRepository.cs | 2 +- FreeSql.sln | 15 +++++ 14 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 Examples/domain_01/Domains/MusicDomain.cs create mode 100644 Examples/domain_01/Entitys/Album.cs create mode 100644 Examples/domain_01/Entitys/AlbumSong.cs create mode 100644 Examples/domain_01/Entitys/Singer.cs create mode 100644 Examples/domain_01/Entitys/Song.cs create mode 100644 Examples/domain_01/Program.cs create mode 100644 Examples/domain_01/Properties/launchSettings.json create mode 100644 Examples/domain_01/Startup.cs create mode 100644 Examples/domain_01/appsettings.Development.json create mode 100644 Examples/domain_01/appsettings.json create mode 100644 Examples/domain_01/domain_01.csproj create mode 100644 Examples/domain_01/readme.md diff --git a/Examples/domain_01/Domains/MusicDomain.cs b/Examples/domain_01/Domains/MusicDomain.cs new file mode 100644 index 00000000..f666e245 --- /dev/null +++ b/Examples/domain_01/Domains/MusicDomain.cs @@ -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 _singerRepostiry => g.orm.GetGuidRepository(); + GuidRepository _albumRepostiry => g.orm.GetGuidRepository(); + GuidRepository _songRepostiry => g.orm.GetGuidRepository(); + GuidRepository _albumSongRepostiry => g.orm.GetGuidRepository(); + + public void SaveSong() { + + } + } +} diff --git a/Examples/domain_01/Entitys/Album.cs b/Examples/domain_01/Entitys/Album.cs new file mode 100644 index 00000000..9221dd4f --- /dev/null +++ b/Examples/domain_01/Entitys/Album.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace domain_01.Entitys +{ + /// + /// 专辑 + /// + public class Album + { + public Guid Id { get; set; } + + public string Name { get; set; } + + public virtual ICollection Songs { get; set; } + + public DateTime PublishTime { get; set; } + } +} diff --git a/Examples/domain_01/Entitys/AlbumSong.cs b/Examples/domain_01/Entitys/AlbumSong.cs new file mode 100644 index 00000000..ff08ccc4 --- /dev/null +++ b/Examples/domain_01/Entitys/AlbumSong.cs @@ -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; } + } +} diff --git a/Examples/domain_01/Entitys/Singer.cs b/Examples/domain_01/Entitys/Singer.cs new file mode 100644 index 00000000..c51fadd9 --- /dev/null +++ b/Examples/domain_01/Entitys/Singer.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace domain_01.Entitys +{ + /// + /// 歌手 + /// + public class Singer + { + public Guid Id { get; set; } + + public string Nickname { get; set; } + + public DateTime RegTime { get; set; } = DateTime.Now; + } +} diff --git a/Examples/domain_01/Entitys/Song.cs b/Examples/domain_01/Entitys/Song.cs new file mode 100644 index 00000000..dec4429a --- /dev/null +++ b/Examples/domain_01/Entitys/Song.cs @@ -0,0 +1,25 @@ +using FreeSql.DataAnnotations; +using System; +using System.Collections.Generic; + +namespace domain_01.Entitys { + + /// + /// 歌曲 + /// + 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 Albums { get; set; } + + public DateTime RegTime { get; set; } = DateTime.Now; + } +} diff --git a/Examples/domain_01/Program.cs b/Examples/domain_01/Program.cs new file mode 100644 index 00000000..87dd792e --- /dev/null +++ b/Examples/domain_01/Program.cs @@ -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(); + } +} diff --git a/Examples/domain_01/Properties/launchSettings.json b/Examples/domain_01/Properties/launchSettings.json new file mode 100644 index 00000000..c671858d --- /dev/null +++ b/Examples/domain_01/Properties/launchSettings.json @@ -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/" + } + } +} \ No newline at end of file diff --git a/Examples/domain_01/Startup.cs b/Examples/domain_01/Startup.cs new file mode 100644 index 00000000..044e7316 --- /dev/null +++ b/Examples/domain_01/Startup.cs @@ -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()) + .UseAutoSyncStructure(true) + .Build(); + } + + public IConfiguration Configuration { get; } + + public void ConfigureServices(IServiceCollection services) { + services.AddSingleton(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; } +} \ No newline at end of file diff --git a/Examples/domain_01/appsettings.Development.json b/Examples/domain_01/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/Examples/domain_01/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/Examples/domain_01/appsettings.json b/Examples/domain_01/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/Examples/domain_01/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Examples/domain_01/domain_01.csproj b/Examples/domain_01/domain_01.csproj new file mode 100644 index 00000000..1e775209 --- /dev/null +++ b/Examples/domain_01/domain_01.csproj @@ -0,0 +1,35 @@ + + + + netcoreapp2.2 + InProcess + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + + diff --git a/Examples/domain_01/readme.md b/Examples/domain_01/readme.md new file mode 100644 index 00000000..784648a5 --- /dev/null +++ b/Examples/domain_01/readme.md @@ -0,0 +1,5 @@ +## 示例项目 domain_01 + +实体:Entitys + +领域:Domains \ No newline at end of file diff --git a/Examples/repository_01/Repositorys/SongRepository.cs b/Examples/repository_01/Repositorys/SongRepository.cs index 1009b3a8..5190e158 100644 --- a/Examples/repository_01/Repositorys/SongRepository.cs +++ b/Examples/repository_01/Repositorys/SongRepository.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace repository_01.Repositorys { public class SongRepository : BaseRepository { - public SongRepository(IFreeSql fsql) : base(fsql) { + public SongRepository(IFreeSql fsql) : base(fsql, null) { } } } diff --git a/FreeSql.sln b/FreeSql.sln index ea9703b0..7d1ef875 100644 --- a/FreeSql.sln +++ b/FreeSql.sln @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Site.DAL", "Example EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Site.UI", "Examples\website\FreeSql.Site.UI\FreeSql.Site.UI.csproj", "{4F1788A6-CD82-41FE-ABFD-D14060708145}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain_01", "Examples\domain_01\domain_01.csproj", "{A23D0455-CA7B-442D-827E-C4C7E84F9084}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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|x86.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -188,6 +202,7 @@ Global {8B4A2173-E0A5-4C0C-A9E9-AE56DA11CF98} = {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} + {A23D0455-CA7B-442D-827E-C4C7E84F9084} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}