开发者

Switching in Entity Framework 4 between SQLCompact and SQLExpress storages

开发者 https://www.devze.com 2023-01-05 11:58 出处:网络
Here\'s the use case In SQLExpress I have created a table Posts with columns ID and Name edmx is created based on that table

Here's the use case

  • In SQLExpress I have created a table Posts with columns ID and Name
  • edmx is created based on that table
  • I create the SQLCompact database with the same structure (table name Posts, columns ID and Name)

If I update the app.config to point to the SqlCompact DB (presuming I do that in correct way), would EF code work seamlessly with SqlCompact db?

The reason why I am asking this is related to the exception I get when trying above

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.S开发者_开发问答etStoreProviderCommandState(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)


Sounds like single edmx can not be used for both sql server and sql compact MSDN Forums link with answer

I am not sure how much this beats the point of edmx, but that is the answer to my question :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号