Hello, I'm trying to use unit testing but faced an issue during seeding data as I'm using EF core but in testing, I'm using SQLite. the issue is that I'm using command * "SET IDENTITY_INSERT [dbo].[...] ON" which we have to use, but it doesn't exist in SQLite. Here is the Exception:
- Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Readzoil.Dpa.DpaTestBaseModule, Readzoil.Dpa.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: SQLite Error 1: 'near "SET": syntax error'.. See the inner exception for details. ---- Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'near "SET": syntax error'.*
So is there a way to fix without commenting these data seedings??
If you're creating a bug/problem report, please include followings:
- ABP Framework version: v7.3.0
- UI type: MVC
- DB provider: EF Core
4 Answer(s)
-
0
Hi,
Are you using SQL code for seeding?
If so, it's not possible, because it doesn't exist in SQLite
You need to use repositories to seed data instead of SQL code
-
0
Hello, I know this but is there a way to solve this one cause I have to use sql code to seed a specific contributor. Like is there a way to know if this contributor is executed by migrator or testing project or is there a way to avoid a specific contributor from execution in testing project??!
-
0
You can try this:
public class MyDatabaseOptions { public string DatabaseProvider { get; set; } public bool IsSqlLite() { return DatabaseProvider == "SqlLite"; } } Configure<AbpDbContextOptions>(options => { Configure<MyDatabaseOptions>(databaseOptions => { databaseOptions.DatabaseProvider = "SqlServer"; }); options.UseSqlServer(); }); public class MyDataSeedContributor : IDataSeedContributor, ITransientDependency { private readonly IIdentityUserRepository _userRepository; private readonly MyDatabaseOptions _myDatabaseOptions; public MyDataSeedContributor(IIdentityUserRepository userRepository, IOptions<MyDatabaseOptions> options) { _userRepository = userRepository; _myDatabaseOptions = options.Value; } public async Task SeedAsync(DataSeedContext context) { if (_myDatabaseOptions.IsSqlLite()) { } } }
-
0
Hello, Thanks, it works fine.