【问题标题】:Switching in Entity Framework 4 between SQLCompact and SQLExpress storages在 SQLCompact 和 SQLExpress 存储之间切换实体框架 4
【发布时间】:2010-07-04 16:01:29
【问题描述】:

这是用例

  • 在 SQLExpress 中,我创建了一个包含 ID 和名称列的 Posts 表
  • edmx 是基于该表创建的
  • 我创建了具有相同结构(表名 Posts、列 ID 和名称)的 SQLCompact 数据库

如果我更新 app.config 以指向 SqlCompact 数据库(假设我以正确的方式执行此操作),EF 代码是否可以与 SqlCompact 数据库无缝协作?

我问这个的原因与我在上面尝试时遇到的异常有关

System.InvalidCastException occurred
  Message=Unable to cast object of type 'System.Data.SqlServerCe.SqlCeConnection' to type 'System.Data.SqlClient.SqlConnection'.
  Source=System.Data
  StackTrace:
       at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
       at System.Data.Common.DbCommand.set_Connection(DbConnection value)
       at System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand)
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
       at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
       at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
       at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
       at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
       at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)

【问题讨论】:

    标签: entity-framework-4 edmx


    【解决方案1】:

    听起来像单个edmx不能同时用于sql server和sql compact MSDN Forums link with answer

    我不确定这比 edmx 有多少意义,但这就是我问题的答案 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      相关资源
      最近更新 更多