0

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);
}
Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • https://stackoverflow.com/questions/8316869/add-an-attribute-to-another-assemblys-class – Kirsten Jan 04 '19 at 18:49
  • 1
    I saw you solved your problem by asking [a similar question](https://www.devexpress.com/Support/Center/Question/Details/T703435/does-xaf-entity-framework-support-sqlite) at the DevExpress support center. Generally, that's the best place for XAF questions. – shamp00 Jan 06 '19 at 21:07
  • 1
    Sometimes it is hard to figure out if it is an XAF , EF or Sqlite question. – Kirsten Jan 06 '19 at 23:10

1 Answers1

0

I had forgotten to fix the initializer

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<Things6DbContext>(modelBuilder);
        Database.SetInitializer(sqliteConnectionInitializer);
    }
Kirsten
  • 15,730
  • 41
  • 179
  • 318