Skip to content

Commit 87a7fcd

Browse files
committed
2 parents 381a904 + c25b833 commit 87a7fcd

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

EFCore.BulkExtensions.MySql/SqlAdapters/MySql/MySqlAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public async Task TruncateAsync(DbContext context, TableInfo tableInfo, Cancella
367367
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
368368
{
369369
Int64.TryParse(reader[0].ToString(), out long result);
370-
hasUniqueConstrain = result == 1;
370+
hasUniqueConstrain = result > 0;
371371
}
372372
}
373373
}
@@ -379,7 +379,7 @@ public async Task TruncateAsync(DbContext context, TableInfo tableInfo, Cancella
379379
while (reader.Read())
380380
{
381381
Int64.TryParse(reader[0].ToString(), out long result);
382-
hasUniqueConstrain = result == 1;
382+
hasUniqueConstrain = result > 0;
383383
}
384384
}
385385
}

EFCore.BulkExtensions.MySql/SqlAdapters/MySql/MySqlQueryBuilder.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,28 @@ public static string DropUniqueConstrain(TableInfo tableInfo)
241241
/// <param name="tableInfo"></param>
242242
public static string HasUniqueConstrain(TableInfo tableInfo)
243243
{
244-
var tableName = tableInfo.TableName;
245-
246-
var uniqueConstrainName = GetUniqueConstrainName(tableInfo);
247-
248-
var q = $@"SELECT DISTINCT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE " +
249-
$@"CONSTRAINT_TYPE = 'UNIQUE' AND CONSTRAINT_NAME = '{uniqueConstrainName}';";
244+
var usedKeyValues = string.Join(",", tableInfo.PrimaryKeysPropertyColumnNameDict.Keys.ToList());
245+
var q = $"""
246+
SELECT COUNT(*) FROM(
247+
SELECT
248+
s.TABLE_SCHEMA,
249+
s.TABLE_NAME,
250+
s.INDEX_NAME,
251+
tc.CONSTRAINT_TYPE,
252+
GROUP_CONCAT(s.COLUMN_NAME ORDER BY s.SEQ_IN_INDEX) AS 'columns_keys'
253+
FROM INFORMATION_SCHEMA.STATISTICS s
254+
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
255+
ON s.TABLE_SCHEMA = tc.TABLE_SCHEMA
256+
AND s.TABLE_NAME = tc.TABLE_NAME
257+
AND s.INDEX_NAME = tc.CONSTRAINT_NAME
258+
where
259+
s.NON_UNIQUE = 0
260+
and s.TABLE_SCHEMA = '{tableInfo.Schema}'
261+
and s.TABLE_NAME = '{tableInfo.TableName}'
262+
GROUP BY s.TABLE_SCHEMA, s.TABLE_NAME, s.INDEX_NAME, tc.CONSTRAINT_TYPE
263+
having columns_keys = '{usedKeyValues}'
264+
) as t
265+
""";
250266
return q;
251267
}
252268

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ Icon>> and Logo (__):
1717
Open source (MIT or cFOSS) authored [.Net libraries](https://infopedia.io/dot-net-libraries/) and other projects (@[**Infopedia.io**](https://infopedia.io/) personal blog post)
1818
|| Project | Type | Description |
1919
| - | ------------------------ | ---- | -------------------------------------------------------- |
20-
| 1* | [EFCore.BulkExtensions](https://github.com/borisdj/EFCore.BulkExtensions) | .Net Lib.(nuget) | EF Core Bulk CRUD Ops (**Flagship** Lib) |
21-
| 2 | [EFCore.UtilExtensions](https://github.com/borisdj/EFCore.UtilExtensions) | .Net Lib.(nuget) | EF Core Custom Annotations and AuditInfo |
22-
| 3 | [EFCore.FluentApiToAnnotation](https://github.com/borisdj/EFCore.FluentApiToAnnotation) | .Net Lib.(nuget) | Converting FluentApi configuration to Annotations |
23-
| 4 | [ExcelIO.FastMapper](https://github.com/borisdj/ExcelIO.FastMapper) | .Net Lib.(nuget) | Excel I/O Mapper to-from Poco & .xlsx with attribute |
24-
| 5 | [FixedWidthParserWriter](https://github.com/borisdj/FixedWidthParserWriter) | .Net Lib.(nuget) | Reading & Writing fixed-width/flat data files |
25-
| 6 | [CsCodeGenerator](https://github.com/borisdj/CsCodeGenerator) | .Net Lib.(nuget) | C# code generation based on Classes and elements |
26-
| 7 | [CsCodeExample](https://github.com/borisdj/CsCodeExample) | C# Code | Examples of C# code in form of a simple tutorial |
20+
| 1* | [EFCore.BulkExtensions](https://github.com/borisdj/EFCore.BulkExtensions) | .Net_Lib(ngt) cF | EF Core Bulk CRUD Ops (**Flagship** Library) |
21+
| 2 | [EFCore.UtilExtensions](https://github.com/borisdj/EFCore.UtilExtensions) | .Net_Lib(ngt) MIT | EF Core Custom Annotations and AuditInfo |
22+
| 3 | [EFCore.FluentApiToAnnotation](https://github.com/borisdj/EFCore.FluentApiToAnnotation) | .Net_Lib(ngt) MIT | Converting FluentApi configuration to Annotations |
23+
| 4 | [ExcelIO.FastMapper](https://github.com/borisdj/ExcelIO.FastMapper) | .Net_Lib(ngt) MIT | Excel I/O Mapper to-from Poco & .xlsx + attribute |
24+
| 5 | [FixedWidthParserWriter](https://github.com/borisdj/FixedWidthParserWriter) | .Net_Lib(ngt) MIT | Reading & Writing fixed-width/flat data files |
25+
| 6 | [CsCodeGenerator](https://github.com/borisdj/CsCodeGenerator) | .Net_Lib(ngt) MIT | C# code generation based on Classes and elements |
26+
| 7 | [CsCodeExample](https://github.com/borisdj/CsCodeExample) | C# Code ( - ) MIT | Examples of C# code in form of a simple tutorial |
2727

2828
## License
29-
BulkExtensions [licensed](https://github.com/borisdj/EFCore.BulkExtensions/blob/master/LICENSE.txt) under [**Dual License**](https://codis.tech/efcorebulk) (**cFOSS**: conditionallyFree OSS - [**OpenSource Sustainability**](https://infopedia.io/solution-to-opensource-sustainability/) & funding).
29+
BulkExtensions [licensed](https://github.com/borisdj/EFCore.BulkExtensions/blob/master/LICENSE.txt) under [**Dual License**](https://codis.tech/efcorebulk) (**cFOSS**: *conditionallyFree* OSS - [**OpenSource Sustainability**](https://infopedia.io/solution-to-opensource-sustainability/) & funding).
3030
If you do not meet criteria for free usage of software with community license then you have to buy commercial one.
3131
If eligible for free usage but still need active support, consider purchasing Starter Lic.
3232

@@ -54,7 +54,7 @@ Instead Test options are SqlServer(Developer or Express), LocalDb(if alongside
5454
## Installation
5555
Available on [![NuGet](https://img.shields.io/nuget/v/EFCore.BulkExtensions.svg)](https://www.nuget.org/packages/EFCore.BulkExtensions/) [![Downloads](https://img.shields.io/nuget/dt/EFCore.BulkExtensions.svg)](https://www.nuget.org/packages/EFCore.BulkExtensions/)
5656
Main nuget is for all Databases, and specific ones with single provider for those who need small packages.
57-
Package manager console command for installation: *Install-Package EFCore.BulkExtensions*
57+
Package manager console command to install: *Install-Package EFCore.BulkExtensions*
5858
Specific ones have adapter suffix: MainNuget + *.SqlServer/PostgreSql/MySql/Oracle/Sqlite*
5959
(
6060
[![](https://img.shields.io/static/v1?label=&message=MS&color=darkred)](https://www.nuget.org/packages/EFCore.BulkExtensions.SqlServer)

0 commit comments

Comments
 (0)