dotnetcore / dotnetcore/FreeSql

ApplyConfigurationsFromAssembly方式配置code first导致stackoverflow异常

Open
#2,081 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
910
PR merge metrics
No merged PRs in 30d

Description

#### 问题描述及重现代码:

使用IEntityTypeConfiguration配置code first的时候,**如果数据库连不上**,查询不会直接报数据库连接不上,而是会直接卡住,然后很久之后报stackoverflow异常,以下配置。随便写一句select,就会报错

```c#
fsql.CodeFirst.ApplyConfigurationsFromAssembly(typeof(BaseEntity).Assembly);
//实体类
///
/// 用户表
///
public class SysAccount() : BaseEntity(), IEntityTypeConfiguration
{
///
/// 邮箱
///
[StringLength(50)]
public string Email { get; set; }

///
/// 手机号
///
[StringLength(20)]
public string Phone { get; set; }

///
/// 昵称
///
[StringLength(20)]
public string? NickName { get; set; }

public string Pwd { get; set; } = string.Empty;

///
/// 状态
///
public AccountStatusEnum Status { get; set; } = AccountStatusEnum.正常;

[StringLength(50)]
public string RegistIp { get; set; }

public void Configure(EfCoreTableFluent model)
{
model.HasIndex(a => a.Email).HasName("idx_account_email").IsUnique();
model.HasIndex(a => a.Phone).HasName("idx_account_phone").IsUnique();
model.HasData(new SysAccount()
{
Email = "xxxx@qq.com",
NickName = "TestUser",
Status = AccountStatusEnum.正常,
RegistIp = "-",
Pwd = "-"
});
}
```

#### 数据库版本
MySQL8.4

#### 安装的Nuget包

#### .net framework/. net core? 及具体版本
.net 9.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.