Új hozzászólás Aktív témák
-
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.TypeLoadExceptionAz 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
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Elemlámpa, zseblámpa
- Docker konténerizálás
- Elektromos autók - motorok
- Samsung Galaxy Felhasználók OFF topicja
- Fejhallgató erősítő és DAC topik
- exHWSW - Értünk mindenhez IS
- Milyen TV-t vegyek?
- Samsung Galaxy S25 Ultra - titán keret, acélos teljesítmény
- Ventilátorok - Ház, CPU (borda, radiátor), VGA
- Okos Otthon / Smart Home
- További aktív témák...
- Dell Inspiron 3593 15,6 Fullhd i7 16Gb SSD256Gb HDD1TB Win11pro
- Újszerű bivaly Lenovo Thinkpad T16 gen3 (13.gen Core Ultra 7 32Gb DDR5 1 Tb SSD) MAGYAR 30 hó GARI!
- Bivaly Lenovo T14 gen5 (Core Ultra 7 32Gb DDR5 1 Tb SSD) laptopom eladó 30 hónap gyártói garanciával
- Bomba ár! Dell Latitude 3410 - i3-10110U I 8GB I 256SSD I HDMI I 13,3" FHD Touch I Cam I W11 I Gari
- Bomba ár! Dell Latitude E5550 - i5-5GEN I 8GB I 128SSD I 15,6" FHD Touch I HDMI I W10 I Cam I Gari!
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest

