Keresés

Új hozzászólás Aktív témák

  • T.Peter

    őstag

    válasz j0k3r! #5953 üzenetére

    Szia. Újrakezdtem az egészet. Tanulom az EF-et, most próbálkozom a model first megközelítéssel, bár itt meg a generálással vannak gondjaim.

  • T.Peter

    őstag

    Sziasztok. Ezt a tutorialt csináltam végig (mvc 5-tel és EF 6.1.1-gyel), de végén a studentcontrollernél exception-t dob.

    An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

    Additional information: Failed to set database initializer of type 'DermatologyWebApplication.DAL.DermatologyWebAppInitializer, DermatologyWebApplication' for DbContext type 'DermatologyWebApplication.DAL.DermatologyWebAppContext, DermatologyWebApplication' specified in the application configuration. See inner exception for details.

    System.InvalidOperationException
    System.TypeLoadException

    Az EF 6.1.1-et nuget-tel tettem az alkalmazásba.
    Próbáltam utánanézni a hibának, de nem találtam releváns segítséget.

    A hibát itt dobja:
    public class DiseaseController : Controller
    {
    private DermatologyWebAppContext db = new DermatologyWebAppContext();

    // GET: Disease
    public ActionResult Index()
    {
    return View(db.Diseases.ToList()); <--------
    }

    Disease.cs:
    public class Disease
    {
    public int Id { get; set; }
    public string Name { get; set; }
    public string Location { get; set; }
    public string Annotation { get; set; }

    public virtual ICollection<DiseaseGroup> DiseaseGroups { get; set; }
    public virtual ICollection<DiseaseSpecification> DiseaseSpecifications { get; set; }
    }

    DermatologyWebAppContext.cs:
    public class DermatologyWebAppContext : DbContext
    {
    public DermatologyWebAppContext() : base("DermatologyWebAppContext")
    {
    }

    public DbSet<Disease> Diseases { get; set; }
    public DbSet<DiseaseGroup> DiseaseGroups { get; set; }
    public DbSet<DiseaseSpecification> DiseaseSpecifications { get; set; }

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

    DermatologyWebAppInitializer.cs:
    public class DermatologyWebAppInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<DermatologyWebAppContext>
    {
    protected override void Seed(DermatologyWebAppContext context)
    {
    var diseases = new List<Disease>
    {
    new Disease{Name = "bőrbetegség1", Location = "Hát", Annotation = "Első megjegyzés"},
    new Disease{Name = "bőrbetegség2", Location = "Váll", Annotation = "Második megjegyzés"},
    new Disease{Name = "bőrbetegség3", Location = "Fenék", Annotation = "Harmadik megjegyzés"},
    new Disease{Name = "bőrbetegség4", Location = "Comb", Annotation = "dfg"},
    new Disease{Name = "bőrbetegség5", Location = "Has", Annotation = "dfg"},
    };

    diseases.ForEach(s => context.Diseases.Add(s));
    context.SaveChanges();

    A web.config-ban ez szerepel:
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

    <connectionStrings>
    <add name="DermatologyWebAppContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDBFilename=|DataDirectory|\DermatologyWebApplicationDB.mdf;Initial Catalog=DermatologyWebApplicationDB;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
    </connectionStrings>

    <entityFramework>
    <contexts>
    <context type="DermatologyWebApplication.DAL.DermatologyWebAppContext, DermatologyWebApplication">
    <databaseInitializer type="DermatologyWebApplication.DAL.DermatologyWebAppInitializer, DermatologyWebApplication" />
    </context>
    </contexts>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="v11.0" />
    </parameters>
    </defaultConnectionFactory>
    <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    </entityFramework>

    Mi az, amit eddig nem vettem észre?

Új hozzászólás Aktív témák