# Cast error using EF5 and MVC4

**URL:** <https://community.miniprofiler.com/t/cast-error-using-ef5-and-mvc4/47>\
**Category:** uncategorized\
**Created:** [November 16, 2012, 9:49pm UTC](https://community.miniprofiler.com/t/cast-error-using-ef5-and-mvc4/47 "2012-11-16T21:49:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stef\_Heyenrath](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/stef_heyenrath/32/431_2.png) [@Stef\_Heyenrath](https://community.miniprofiler.com/u/Stef_Heyenrath)\
**Post date:** [November 16, 2012, 9:49pm UTC](https://community.miniprofiler.com/t/cast-error-using-ef5-and-mvc4/47/1 "2012-11-16T21:49:29Z")

</div>

I’m using **EF5** and **MVC4**. And **Code First**.

I’ve the following connection string:

```
<connectionStrings>
  <add name="MyDataContext" connectionString="Data Source=|DataDirectory|DemoData.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

```

When I use MiniProfilerEF.Initialize(false) in Global.asax.cs, I get an error when executing a query.Count()

```
Unable to cast object of type 'StackExchange.Profiling.Data.EFProfiledDbConnection' to type 'System.Data.SqlServerCe.SqlCeConnection'.
```
