Integrating SQLServer Express

Oct 24, 2011 at 9:49 PM

I'm trying to reverse-engineer the completed (3.0b) project and integrate an external SQL Express db.

I've created the db with the included script

I've changed the connection string to:

connectionString="Data Source=.\Dev;Initial Catalog=MvcMusicStore;Integrated Security=True"
     providerName="System.Data.SqlClient"/>

In Global.asax I've added 'Database.SetInitializer<MyAppEntities>(null);' as is referenced on another thread.

I know i have several of the ducks correctly lined up because breakpoints show valid (populated) objects at the HomeController's Index method. However, the next step ( return storeDB.Albums) results in Invalid object name 'dbo.Albums'

I'm brand new to EF and not that deep in ORM but, based on the Album/Albums discrepancy (singular in the db and plural when the breakpoint hits)  it looks like the plumbing between EF and the DB is missing some requisite pipe. But since stuff compiles and at least _some is working correctly .... i'm stuck and highly appreciative of any help.

   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.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MyApp.Controllers.HomeController.GetTopSellingAlbums(Int32 count) in F:\Code\MyApp\MyApp\Controllers\HomeController.cs:line 28
   at MyApp.Controllers.HomeController.Index() in F:\Code\MyApp\MyApp\Controllers\HomeController.cs:line 18
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

Coordinator
Oct 24, 2011 at 10:10 PM

I'd highly recommend using SQL CE rather than SQL Express if at all possible. Any reason why you can't do that?

The latest SQL Script should have the pluralization for the tables correct, but if it's not working take a look at this post on how to control the pluralization settings for Entity Framework: http://stevesmithblog.com/blog/entity-framework-invalid-object-name-dbo-albums/

Oct 24, 2011 at 11:32 PM
jongalloway wrote:

I'd highly recommend using SQL CE rather than SQL Express if at all possible. Any reason why you can't do that?

Does that recommendation hold for production-oriented sites, or limited to the learning curve process. All my management and maintenance experience is SSMS-based though for all I know, things may be equivalent between the two.

Can you paint a picture of a dev workflow that transitions from CE to Express? You'd expect all dev work to take place in CE then build an Express db from script when entering production?

Thankx much for the time!

Oct 25, 2011 at 1:32 AM
jongalloway wrote:

The latest SQL Script should have the pluralization for the tables correct, but if it's not working take a look at this post on how to control the pluralization settings for Entity Framework: http://stevesmithblog.com/blog/entity-framework-invalid-object-name-dbo-albums/

ModelBuilder reference wasn't found but this seems to work:

        protected override void OnModelCreating(DbModelBuilder dbModelBuilder)
        {
            dbModelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }