mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	add examples domain_01
This commit is contained in:
		
							
								
								
									
										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
 | 
			
		||||
		Reference in New Issue
	
	Block a user