Ошибка логики SQL: нет такой таблицы: перенос стандартной безопасности xaf на Sqlite - PullRequest
0 голосов
/ 04 января 2019

Я пытаюсь заставить проект XAF Winforms работать с SQLite. Я использую Entity Framework 6 Code First со стандартной безопасностью.

Когда я запускаю проект, я получаю

SQL logic error
no such table: PermissionPolicyUsers

   at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

В DbContext у меня есть

public class Things5DbContext : DbContext {
    public Things5DbContext(String connectionString)
        : base(new SQLiteConnection() { ConnectionString = connectionString }, true)

    {
    }
    public Things5DbContext(DbConnection connection)
        : base(connection, false) {
    }
    public Things5DbContext()
        : base("name=ConnectionString") {
    }
    public DbSet<ModuleInfo> ModulesInfo { get; set; }
    public DbSet<PermissionPolicyRole> Roles { get; set; }
    public DbSet<PermissionPolicyTypePermissionObject> TypePermissionObjects { get; set; }
    public DbSet<PermissionPolicyUser> Users { get; set; }
    public DbSet<ModelDifference> ModelDifferences { get; set; }
    public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; }
}

Полагаю, что если бы у меня был доступ к классу PermissionPolicyUser, я мог бы применить атрибут

[Table("Users")]  and rename the DbSet to PermissionPolicyUsers

Однако класс определен в библиотеке Dev Express

DevExpress.Persistent.BaseImpl.EF.PermissionPolicy

Оказывается, что в базе данных не создаются таблицы.

Я попробовал следующее, но это не помогло

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<PermissionPolicyRole>().ToTable("PermissionPolicyRoleBases");
    modelBuilder.Entity<PermissionPolicyUser>().ToTable("PermissionPolicyUsers");
    modelBuilder.Entity<PermissionPolicyTypePermissionObject>().ToTable("PermissionPolicyTypePermissionObjects");

    base.OnModelCreating(modelBuilder);
}

1 Ответ

0 голосов
/ 07 января 2019

Я забыл исправить инициализатор

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<Things6DbContext>(modelBuilder);
        Database.SetInitializer(sqliteConnectionInitializer);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...