Ошибка SQLiteException SQL logi c при отсутствии такого столбца - PullRequest
0 голосов
/ 24 апреля 2020

У меня есть приложение WPF, которое будет читать и записывать данные из файла Sqlite. Файл БД существует и не создается во время выполнения. Я использую Entity Framework 6 Code First без миграции. Также используются сборки для System.Data.SQLite. Вот мой app.config:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>  
    <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="UserContext" connectionString="Data Source=.\DataFile\user.sqlite" providerName="System.Data.SQLite" />
    <add name="AnalysisContext" connectionString="Data Source=.\DataFile\analysis.sqlite" providerName="System.Data.SQLite" />
  </connectionStrings>

</configuration>

Вот мой DBContext:

class AnalysisContext : DbContext
{
public AnalysisContext()
{

}

public DbSet<AnalysisHeader> AnalysisHeaders { get; set; }
public DbSet<AnalysisDataRequired> AnalysisDataRequired { get; set; }
public DbSet<AnalysisSummary> AnalysisSummaryRows { get; set; }
public DbSet<AnalysisEscalation> AnalysisEscalations { get; set; }
public DbSet<BaselineDataSource> BaselineDataSources { get; set; }
public DbSet<BasisEscalation> BasisEscalations { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<AnalysisHeader>().ToTable("AnalysisHeader");
    modelBuilder.Entity<AnalysisDataRequired>().ToTable("AnalysisDataRequired");
    modelBuilder.Entity<AnalysisSummary>().ToTable("AnalysisSummary");
    modelBuilder.Entity<AnalysisEscalation>().ToTable("AnalysisEscalation");
    modelBuilder.Entity<BaselineDataSource>().ToTable("BaselineDataSource");
    modelBuilder.Entity<BasisEscalation>().ToTable("BasisEscalation");
    base.OnModelCreating(modelBuilder);
}

}

Вот моя модель:

[Table("BaselineDataSource")]
    public class BaselineDataSource
    {
        [Key]
        [Column("ValueText")]
        public string ValueText { get; set; }
    }

    [Table("BasisEscalation")]
    public class BasisEscalation
    {
        [Key]
        [Column("ValueText")]
        public string ValueText { get; set; }
    }

У меня есть несколько моделей, которые в целом одинаковы. Когда этот метод в модели представления выполняется:

public void GetBaselineList()
        {
            AnalysisContext db = new AnalysisContext();
            List<BaselineDataSource> list = db.BaselineDataSources.ToList();
            foreach (var item in list)
            {
                BaselineDataSourceList.Add(new BaselineDataSource() { ValueText = item.ValueText });
            }
        }

Я получаю ошибку:

System.Data.Entity.Core.EntityCommandExecutionException
  HResult=0x8013193C
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__1()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass41_0.<GetResults>b__0()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ChellGovTools.ViewModels.ImportWizardViewModel.GetBaselineList() in C:\Users\ryans\source\repos\ChellGOV\ChellGovTools\ViewModels\ImportWizardViewModel.cs:line 264
   at ChellGovTools.ViewModels.ImportWizardViewModel..ctor() in C:\Users\ryans\source\repos\ChellGOV\ChellGovTools\ViewModels\ImportWizardViewModel.cs:line 136
   at ChellGovTools.ImportWizard..ctor() in C:\Users\ryans\source\repos\ChellGOV\ChellGovTools\Views\ImportWizard.xaml.cs:line 20

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
SQLiteException: SQL logic error
no such column: Extent1.ValueText

Я снова и снова подтверждал, что в базе данных есть все ожидаемые таблицы и столбцы как а также данные. EF, кажется, находит базу данных в порядке, но не может прочитать коллекцию столбцов. Я не уверен, что попробовать дальше. Я нашел другие посты и статьи, но они были сосредоточены на создании базы данных во время выполнения, чего нет в наших спецификациях. Пожалуйста, дайте мне знать, что еще я могу опубликовать, чтобы решить эту проблему подключения. Спасибо

...