dotnetcore / dotnetcore/FreeSql

AsTable方法不起作用

Open
#1,916 2 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

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

基本需求是,读取数据表A里的数据,筛掉部分数据之后之后,将有效数据写入数据表A_fix,想通过 AsTable 来指定写入数据表的表名。
我写了以下方法来实现,但是发现执行的SQL代码中,并不是newtablename表名,而是原来的默认表名(TableAttribute指定的表名)。
PS:我的写入数据库是达梦的

```c#
// c# code
///
/// 替换表格数据
///
/// 数据类型
/// 数据列表
/// 数据库
/// 表名尾缀,基于原表名增加的尾缀
///
private void replaceTableData(List dataList, IFreeSql db, string tableNameSuffix) where T : class
{
// 获取类型
var type = typeof(T);
// 获取 Table 特性
var tableAttribute = type.GetCustomAttribute();
// 新表名
var newtablename = tableAttribute.Name + tableNameSuffix;

try
{
var delResult = db.Delete().AsTable(newtablename).Where(q => true).ExecuteAffrows();
}
catch (Exception er)
{
Log4NetExtension.GetLogger().Error($"[{type.FullName}]删除表数据时发生异常", er);
}
var insResult = db.Insert(dataList).AsTable(newtablename).ExecuteAffrows();
}
```

#### 数据库版本

#### 安装的Nuget包

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

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.