The type arguments for method 'System.Data.Entity.Database.SetInitializer<TContext>(System.Data.Entity.IDatabaseInitializer<TContext>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
____________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{ System.Data.Entity.Database.SetInitializer(
new TutorialMusicStore.Models.SampleData());
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
The type arguments for method 'System.Data.Entity.Database.SetInitializer<TContext>(System.Data.Entity.IDatabaseInitializer<TContext>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Hello:)
Please make sure that you've referred the EntityFramework.dll successfully,and then refer the namespace of
using System.Data.Entity;
And then directly use DataBase.SetSerializer(……); But your class should also implement the interface of IDatabaseInitializer<TContext>.
Reguards!
3v3rhart
Member
159 Points
317 Posts
Music Store Tutorial - Error: System.Data.Entity.Database.SetInitializer
Jun 20, 2012 05:10 PM|LINK
Error:
The type arguments for method 'System.Data.Entity.Database.SetInitializer<TContext>(System.Data.Entity.IDatabaseInitializer<TContext>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
____________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace TutorialMusicStore
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
System.Data.Entity.Database.SetInitializer(
new TutorialMusicStore.Models.SampleData());
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
3v3rhart
Member
159 Points
317 Posts
Re: Music Store Tutorial - Error: System.Data.Entity.Database.SetInitializer
Jun 20, 2012 05:30 PM|LINK
...forgot to specify that the code above is from global.asax file.
tdykstra
Contributor
4523 Points
630 Posts
Microsoft
Moderator
Re: Music Store Tutorial - Error: System.Data.Entity.Database.SetInitializer
Jun 20, 2012 09:13 PM|LINK
For an example of how to call SetInitializer, see this tutorial:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Music Store Tutorial - Error: System.Data.Entity.Database.SetInitializer
Jun 22, 2012 12:12 AM|LINK
Hello:)
Please make sure that you've referred the EntityFramework.dll successfully,and then refer the namespace of
using System.Data.Entity;
And then directly use DataBase.SetSerializer(……); But your class should also implement the interface of IDatabaseInitializer<TContext>.
Reguards!
hillscottc
Member
4 Points
4 Posts
Re: Music Store Tutorial - Error: System.Data.Entity.Database.SetInitializer
Jul 24, 2012 08:08 AM|LINK
All you need to do is make reference to the System.Data.Entity and your App's model namesspaces. Like so:
That should do the trick.