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

Truncate does not work on SQLite #272

Open
csname1910 opened this issue Dec 16, 2019 · 6 comments
Open

Truncate does not work on SQLite #272

csname1910 opened this issue Dec 16, 2019 · 6 comments
Labels

Comments

@csname1910
Copy link

Truncate does not work on SQLite because dbo is added.

This SQL-Command is generated:
DELETE FROM [dbo].[Customers];VACUUM;

SqliteException: SQLite Error 1: 'no such table: dbo.Customers'.

The right command should be:
DELETE FROM [Customers];VACUUM;

@doesbaddel
Copy link

Same issue here.

Problem is in TableInfo.cs Line 92, where the default value 'dbo' is set:
Schema = entityType.GetSchema() ?? "dbo";

@borisdj borisdj added the bug label Mar 28, 2020
@borisdj
Copy link
Owner

borisdj commented Mar 28, 2020

Fix:

bool isSqlServer = context.Database.ProviderName.EndsWith(DbServer.SqlServer.ToString());
string defaultSchema = isSqlServer ? "dbo" : null;
Schema = entityType.GetSchema() ?? defaultSchema;

Will publish this fix in the next version.

@borisdj
Copy link
Owner

borisdj commented Sep 21, 2020

Fixed

@borisdj borisdj closed this as completed Sep 21, 2020
@Insire
Copy link

Insire commented Oct 18, 2022

This seems to be broken again.

dbcontext.Truncate<MyTableModel>();

generates the following sql with ef core 6.0.10

DELETE FROM [dbo].[MyTable];VACUUM;

which throws

Exception thrown: 'Microsoft.Data.Sqlite.SqliteException' in Microsoft.EntityFrameworkCore.Relational.dll
SQLite Error 1: 'no such table: dbo.MyTable'.

Looking at the previous solution (dropping the schema), the cause seems to be

    /// <inheritdoc/>
    public void Truncate(DbContext context, TableInfo tableInfo)
    {
        string sql = SqlQueryBuilder.DeleteTable(tableInfo.FullTableName);
        context.Database.ExecuteSqlRaw(sql);
    }

where FullTableName is defined as public string FullTableName => $"{SchemaFormated}[{TableName}]";

@LeDahu22
Copy link

@borisdj It seems the schema is still added with the latest version on SQLite (8.0.2), causing the truncate to fail

@borisdj borisdj reopened this Mar 11, 2024
@borisdj
Copy link
Owner

borisdj commented Mar 11, 2024

Will take a look.

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

No branches or pull requests

5 participants