efcore 8 json 列测试完毕
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
760321f8fa
commit
1f33a9fa4e
|
@ -2327,7 +2327,7 @@
|
|||
<param name="_hostEnvironment"></param>
|
||||
</member>
|
||||
<!-- Badly formed XML comment ignored for member "T:IRaCIS.Core.Application.Service.MinimalApiService.TestMinimalApiService" -->
|
||||
<!-- Badly formed XML comment ignored for member "M:IRaCIS.Core.Application.Service.MinimalApiService.TestMinimalApiService.#ctor(IRaCIS.Core.Domain.Share.IUserInfo)" -->
|
||||
<!-- Badly formed XML comment ignored for member "M:IRaCIS.Core.Application.Service.MinimalApiService.TestMinimalApiService.#ctor(IRaCIS.Core.Domain.Share.IUserInfo,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Infra.EFCore.TestLength})" -->
|
||||
<member name="M:IRaCIS.Core.Application.Service.OAuthService.TestClientCredentialsAsync">
|
||||
<summary>
|
||||
测试客户端凭证代码
|
||||
|
|
|
@ -21,10 +21,54 @@ namespace IRaCIS.Core.Application.Service.MinimalApiService
|
|||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "Institution")]
|
||||
|
||||
public class TestMinimalApiService(IUserInfo _userInfo) : ServiceBase
|
||||
public class TestMinimalApiService(IUserInfo _userInfo, IRepository<TestLength> _testLengthRepository) : ServiceBase
|
||||
{
|
||||
|
||||
|
||||
public async Task<IResponseOutput> TestEfcoreJson()
|
||||
{
|
||||
|
||||
var dateTime = DateTime.Parse("2024-11-08");
|
||||
|
||||
//await _testLengthRepository.AddAsync(new TestLength()
|
||||
//{
|
||||
// Name = "Testddd",
|
||||
// TestJsonObjectLsit=new List<TestJsonObject>() { new TestJsonObject() { Name="name1",Description="des1"} , new TestJsonObject() { Name = "name1", Description = "des1" } }
|
||||
//});
|
||||
|
||||
//await _testLengthRepository.SaveChangesAsync();
|
||||
|
||||
//对于json 对象 不能使用count any 操作,但是简单的类型可以的
|
||||
var jobjectList = _testLengthRepository.AsQueryable().ToList();
|
||||
|
||||
|
||||
var d1 = _testLengthRepository.Where(t => t.StringList.Any(t => t == "string1")).ToList();
|
||||
var d2 = _testLengthRepository.Where(t => t.StringList.Contains("string1")).ToList();
|
||||
|
||||
//selectMany 报错 不支持
|
||||
//var d20 = _testLengthRepository.Where(t => t.StringList.Contains("string1")).SelectMany(t => t.StringList).ToList();
|
||||
|
||||
var d3 = _testLengthRepository.Where(t => t.TestEnumList.Contains(TestEnum.Default)).ToList();
|
||||
var d4 = _testLengthRepository.Where(t => t.TestEnumList.Any(t => t == TestEnum.Default)).ToList();
|
||||
|
||||
var d5 = _testLengthRepository.Where(t => t.DateTimeList.Contains(dateTime)).ToList();
|
||||
var d6 = _testLengthRepository.Where(t => t.DateTimeList.Any(t => t == dateTime)).ToList();
|
||||
|
||||
var d7 = _testLengthRepository.Where(t=>t.DateTimeList.Any(t=>t.Year==2024)).ToList();
|
||||
|
||||
var d8 = _testLengthRepository.Where(t => t.DateTimeList.Any(t => t.Month == 11)).ToList();
|
||||
|
||||
var d90 = _testLengthRepository.Where(t => t.DateTimeList.Any(t => t.Year == 2024)).Select(t => t.DateTimeList).ToList();
|
||||
|
||||
//selectMany 报错 不支持
|
||||
//var d9 = _testLengthRepository.Where(t => t.DateTimeList.Any(t => t.Year == 2024)).SelectMany(t=>t.DateTimeList).ToList();
|
||||
//var d10 = _testLengthRepository.Where(t => t.DateTimeList.Any(t => t.Year == 2024)).SelectMany(t => t.DateTimeList).Where(t=>t>dateTime.AddSeconds(1)).ToList();
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TrialGlobalLimit("AddOrUpdateTrial", "BeforeOngoingCantOpt", "AfterStopCannNotOpt")]
|
||||
public Task<List<string>> GetProjectList1Async()
|
||||
{
|
||||
|
@ -38,7 +82,7 @@ namespace IRaCIS.Core.Application.Service.MinimalApiService
|
|||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[TrialGlobalLimit( "BeforeOngoingCantOpt")]
|
||||
[TrialGlobalLimit("BeforeOngoingCantOpt")]
|
||||
public IResponseOutput GetTest()
|
||||
{
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using IRaCIS.Core.Domain.Models;
|
|||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
using IRaCIS.Core.Infrastructure.Encryption;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Newtonsoft.Json;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
|
@ -59,11 +60,13 @@ public class IRaCISDBContext : DbContext
|
|||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
modelBuilder.Entity<TestLength>(entity =>
|
||||
{
|
||||
// 使用部分加密值转换器,前 2 个字符不加密,方便模糊搜索
|
||||
entity.Property(e => e.Name)
|
||||
.HasConversion(new PartialEncryptionConverter(2));
|
||||
entity.Property(e => e.Name).HasConversion(new PartialEncryptionConverter(2));
|
||||
entity.Property(e => e.TestJsonObjectLsit).HasConversion(v => v == null ? "[]" : JsonConvert.SerializeObject(v),
|
||||
v => string.IsNullOrEmpty(v) ? null : JsonConvert.DeserializeObject<List<TestJsonObject>>(v));
|
||||
});
|
||||
|
||||
#region pgsql codefirst 配置 暂时屏蔽
|
||||
|
@ -558,7 +561,7 @@ public class IRaCISDBContext : DbContext
|
|||
|
||||
public virtual DbSet<TestLength> TestLength { get; set; }
|
||||
|
||||
public virtual DbSet<EventStoreRecord> EventStoreRecord { get; set; }
|
||||
public virtual DbSet<EventStoreRecord> EventStoreRecord { get; set; }
|
||||
|
||||
|
||||
|
||||
|
@ -567,6 +570,32 @@ public class IRaCISDBContext : DbContext
|
|||
public class TestLength : Entity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
[StringLength(1000)]
|
||||
public string[] StringList { get; set; }=new string[] { };
|
||||
|
||||
public List<DateTime> DateTimeList { get; set; } = new List<DateTime>();
|
||||
|
||||
[StringLength(1000)]
|
||||
public List<TestEnum> TestEnumList { get; set; } = new List<TestEnum>();
|
||||
|
||||
[MaxLength]
|
||||
public List<TestJsonObject> TestJsonObjectLsit { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public struct TestJsonObject
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
public enum TestEnum
|
||||
{
|
||||
Default = 0,
|
||||
|
||||
First = 1
|
||||
}
|
||||
|
||||
|
||||
|
|
18080
IRaCIS.Core.Infra.EFCore/Migrations/20241108013005_TestEfcoreJson.Designer.cs
generated
Normal file
18080
IRaCIS.Core.Infra.EFCore/Migrations/20241108013005_TestEfcoreJson.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class TestEfcoreJson : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "DateTimeList",
|
||||
table: "TestLength",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "[]");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "StringList",
|
||||
table: "TestLength",
|
||||
type: "nvarchar(1000)",
|
||||
maxLength: 1000,
|
||||
nullable: false,
|
||||
defaultValue: "[]");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "TestEnumList",
|
||||
table: "TestLength",
|
||||
type: "nvarchar(1000)",
|
||||
maxLength: 1000,
|
||||
nullable: false,
|
||||
defaultValue: "[]");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DateTimeList",
|
||||
table: "TestLength");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "StringList",
|
||||
table: "TestLength");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TestEnumList",
|
||||
table: "TestLength");
|
||||
}
|
||||
}
|
||||
}
|
18084
IRaCIS.Core.Infra.EFCore/Migrations/20241108051348_TestJsonObject.Designer.cs
generated
Normal file
18084
IRaCIS.Core.Infra.EFCore/Migrations/20241108051348_TestJsonObject.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class TestJsonObject : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "TestJsonObjectLsit",
|
||||
table: "TestLength",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TestJsonObjectLsit",
|
||||
table: "TestLength");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13744,11 +13744,29 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("DateTimeList")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b.Property<string>("StringList")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("nvarchar(1000)");
|
||||
|
||||
b.Property<string>("TestEnumList")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("nvarchar(1000)");
|
||||
|
||||
b.Property<string>("TestJsonObjectLsit")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TestLength");
|
||||
|
|
Loading…
Reference in New Issue