在VS2017或者更高的版本中
可以在程序集的属性来修改,如下:
也可以按照如下方式修改代码:
1 <Project Sdk="Microsoft.NET.Sdk"> 2 3 <PropertyGroup> 4 <TargetFramework>net6.0</TargetFramework> 5 <ImplicitUsings>enable</ImplicitUsings> 6 <Nullable>enable</Nullable> 7 </PropertyGroup> 8 9 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> 10 <DefineConstants>$(DefineConstants);INIT_DB</DefineConstants> 11 </PropertyGroup> 12 13 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> 14 <DefineConstants>$(DefineConstants);INIT_DB</DefineConstants> 15 </PropertyGroup> 16 17 <ItemGroup> 18 <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> 19 <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> 20 <PackageReference Include="SqlSugarCore" Version="5.1.2.2" /> 21 </ItemGroup> 22 23 <ItemGroup> 24 <ProjectReference Include="..\Common.Domain\Common.Domain.csproj" /> 25 </ItemGroup> 26 27 </Project>
文件中的使用方案:
#if INIT_DB //only when your want to init db ConfigureExternalServices = new ConfigureExternalServices { EntityService = (c, p) => { if (p.PropertyName.Equals(nameof(Common.Domain.LogicDeleted.IsDeleted))) { p.IsPrimarykey = true; } } }, #endif