2

这是用例

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

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

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

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)
4

1 回答 1

2

听起来像单个 edmx 不能同时用于 sql server 和 sql compact MSDN 论坛链接与答案

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

于 2010-07-05T08:20:05.417 回答