Skip to content

Commit 2d2a0e2

Browse files
2881028810
authored andcommitted
- 增加 Oracle DbFirst 视图的支持;
1 parent bf84bf0 commit 2d2a0e2

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

Extensions/FreeSql.Generator/FreeSql.Generator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Description>使用 FreeSql 快速生成数据库的实体类,安装:dotnet tool install -g FreeSql.Generator</Description>
1313
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
15-
<Version>1.9.0-preview0920</Version>
15+
<Version>1.8.1.330</Version>
1616
<PackageTags>FreeSql DbFirst 实体生成器</PackageTags>
1717
</PropertyGroup>
1818

FreeSql.Tests/FreeSql.Tests/Oracle/OracleDbFirstTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public void GetTableByName()
3333
Assert.Equal(t1.Columns.Count, t2.Columns.Count);
3434
var t3 = fsql.DbFirst.GetTableByName("notexists_tb");
3535
Assert.Null(t3);
36+
37+
var t4 = fsql.DbFirst.GetTableByName("V_DTOS_DT");
3638
}
3739

3840
[Fact]

FreeSql.Tests/FreeSql.Tests/SqlServer/SqlServerAdo/SqlServerAdoTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FreeSql.DataAnnotations;
22
using FreeSql.Tests.DataContext.SqlServer;
3+
using Microsoft.Data.SqlClient;
34
using NetTaste;
45
using System;
56
using System.Collections.Generic;
@@ -47,7 +48,14 @@ public void ExecuteArray()
4748
[Fact]
4849
public void ExecuteNonQuery()
4950
{
50-
51+
var ps = new[]
52+
{
53+
new SqlParameter("@TableName", "tb1"),
54+
new SqlParameter("@FInterID", System.Data.SqlDbType.Int)
55+
};
56+
ps[1].Direction = System.Data.ParameterDirection.Output;
57+
g.sqlserver.Ado.ExecuteNonQuery(System.Data.CommandType.StoredProcedure, "dbo.GetICMaxNum", ps);
58+
Assert.Equal(100, ps[1].Value);
5159
}
5260
[Fact]
5361
public void ExecuteScalar()

Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleDbFirst.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,27 @@ public List<DbTableInfo> GetTables(string[] database, string tablename, bool ign
216216
var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a)));
217217
var sql = $@"
218218
select
219-
a.owner || '.' || a.table_name,
219+
a.owner || '.' || a.table_name AS tbname,
220220
a.owner,
221221
a.table_name,
222222
b.comments,
223-
'TABLE'
223+
'TABLE' AS tp
224224
from all_tables a
225225
left join all_tab_comments b on b.owner = a.owner and b.table_name = a.table_name and b.table_type = 'TABLE'
226-
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.table_name)" : "a.table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}";
226+
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.table_name)" : "a.table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}
227+
228+
UNION ALL
229+
230+
select
231+
a.owner || '.' || a.view_name,
232+
a.owner,
233+
a.view_name,
234+
b.comments,
235+
'VIEW' AS tp
236+
from all_views a
237+
left join all_tab_comments b on b.owner = a.owner and b.table_name = a.view_name and b.table_type = 'VIEW'
238+
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.view_name)" : "a.view_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}
239+
";
227240
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
228241
if (ds == null) return loc1;
229242

Providers/FreeSql.Provider.Oracle/OracleDbFirst.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,27 @@ public List<DbTableInfo> GetTables(string[] database, string tablename, bool ign
216216
var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a)));
217217
var sql = $@"
218218
select
219-
a.owner || '.' || a.table_name,
219+
a.owner || '.' || a.table_name AS tbname,
220220
a.owner,
221221
a.table_name,
222222
b.comments,
223-
'TABLE'
223+
'TABLE' AS tp
224224
from all_tables a
225225
left join all_tab_comments b on b.owner = a.owner and b.table_name = a.table_name and b.table_type = 'TABLE'
226-
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.table_name)" : "a.table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}";
226+
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.table_name)" : "a.table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}
227+
228+
UNION ALL
229+
230+
select
231+
a.owner || '.' || a.view_name,
232+
a.owner,
233+
a.view_name,
234+
b.comments,
235+
'VIEW' AS tp
236+
from all_views a
237+
left join all_tab_comments b on b.owner = a.owner and b.table_name = a.view_name and b.table_type = 'VIEW'
238+
where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.view_name)" : "a.view_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}
239+
";
227240
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
228241
if (ds == null) return loc1;
229242

0 commit comments

Comments
 (0)