Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Aop.ConfigEntity 不应该在不同IFreeSql实例间共享 #1729

Closed
tky753 opened this issue Jan 30, 2024 · 2 comments
Closed

.Aop.ConfigEntity 不应该在不同IFreeSql实例间共享 #1729

tky753 opened this issue Jan 30, 2024 · 2 comments

Comments

@tky753
Copy link
Contributor

tky753 commented Jan 30, 2024

问题描述及重现代码:

// c# code
var fsql1 = new FreeSqlBuilder().UseConnectionString(DataType.SqlServer,  “...Database=xxx;....”);
var fsql2 = new FreeSqlBuilder().UseConnectionString(DataType.SqlServer,  “...Database=yyy;...);

(fsql2 as BaseDbProvider)!.InternalCommonUtils._mappingPriorityTypes = [
            MappingPriorityType.Attribute,
            MappingPriorityType.FluentApi,
            MappingPriorityType.Aop
        ];
fsql2.Aop.ConfigEntity += (_, c) => {
  c.ModifyResult.Name = $"[xxx].[dbo].[{c.ModifyResult.Name}]";
};

await fsql1.Select<Entity>().Where(a => false).ToListAsync();
await fsql2.Select<Entity>().Where(a => false).ToListAsync();  //上面的ConfigEntity 不会调用,导致语句出错
// 希望的语句:SELECT a.[Id] FROM [xxx].[dbo].[table] a WHERE (1=2)
// 实际的语句:SELECT a.[Id] FROM [table] a WHERE (1=2)

[Table(Name="table")]
class Entity
{
  public long Id {get; set;}
}

数据库版本

Sql Server 2008 R2

安装的Nuget包

FreeSql.Provider.SqlServer 3.2.811

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

net8.0

@2881099
Copy link
Collaborator

2881099 commented Jan 30, 2024

不是 aop.configEntity 共享问题。

FreeSql 设计 DataType.SqlServer 下的一个实体类型,只存在一个影射。

同一个实体类型,在不同 DataType 下映射可以不同。

@tky753
Copy link
Contributor Author

tky753 commented Jan 31, 2024

感觉有些反直觉。如果Aop映射做成静态的可能更不容易搞错(虽然那样的话要多传一个DataType)。
早知道了的话,像是Sql Server需要在不同数据库间 join查询的,设计的时候就直接写成[Table(Name="xxx.dbo.table")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants