Entity framework 4 在实体框架4中,在SQLCompact和SQLExpress存储之间切换
下面是用例Entity framework 4 在实体框架4中,在SQLCompact和SQLExpress存储之间切换,entity-framework-4,edmx,Entity Framework 4,Edmx,下面是用例 在SQLExpress中,我创建了一个带有列ID和列名称的Posts表 edmx是基于该表创建的 我创建了具有相同结构的SQLCompact数据库(表名、列ID和名称) 如果我更新app.config以指向SqlCompact数据库(假设我以正确的方式这样做),EF代码会与SqlCompact数据库无缝工作吗? 我问这个问题的原因与我在上面尝试时遇到的异常有关 System.InvalidCastException occurred Message=Unable to cas
- 在SQLExpress中,我创建了一个带有列ID和列名称的Posts表
- edmx是基于该表创建的
- 我创建了具有相同结构的SQLCompact数据库(表名、列ID和名称)
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)
发生System.InvalidCastException异常
Message=无法将“System.Data.SqlServerCe.SqlCeConnection”类型的对象强制转换为“System.Data.SqlClient.SqlConnection”类型。
Source=System.Data
堆栈跟踪:
在System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection值)处
at System.Data.Common.DbCommand.set_Connection(DbConnection值)
位于System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand和EntityCommand、EntityTransaction、EntityTransaction和DbCommand storeProviderCommand)
位于System.Data.EntityClient.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior)
在System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext上下文,ObjectParameterCollection parameterValues)
位于System.Data.Objects.ObjectQuery`1.GetResults(可为null`1 forMergeOption)
位于System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
位于System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1源)
在System.Data.Objects.Elink.ObjectQueryProvider.b__1[TResult](IEnumerable`1序列)
在System.Data.Objects.Elink.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1查询,表达式queryRoot)
位于System.Data.Objects.Elink.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](表达式)
位于System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1源)
听起来单个edmx不能同时用于sql server和sql compact 我不确定这在多大程度上超过了edmx的重点,但这就是我问题的答案:)