2010-07-04 61 views
2

SQLCompact,而SQLEXPRESS儲藏間這裏的用例交換在實體框架4

  • 在的SQLExpress我創建
  • EDMX是基於表
  • 我創建了列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) 

回答

2

想,當我得到的原因聽起來像是一個EDMX不能同時用於SQL Server和SQL緊湊 MSDN Forums link with answer

我不知道這是多少EDMX點,但這是我的問題的答案:)

+0

非常討厭。 – 2012-07-19 13:59:20