SQL logic error no such table: porting xaf standard security to Sqlite

entity-framework-6 sqlite xaf

Question

I am trying to make an XAF Winforms project run with SQLite. I am using Entity Framework 6 Code First with Standard Security.

When I run the project I get

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)

In the DbContext I have

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; }
}

I guess that if I had access to the PermissionPolicyUser class I could apply an attribute

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

However the class is defined in the Dev Express library

DevExpress.Persistent.BaseImpl.EF.PermissionPolicy

It turns out that no tables are being created in the database.

I tried the following but it did not help

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
1/4/2019 9:01:55 PM

Accepted Answer

I had forgotten to fix the initializer

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<Things6DbContext>(modelBuilder);
        Database.SetInitializer(sqliteConnectionInitializer);
    }
0
1/6/2019 11:09:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow