Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

SQLITE EF6.1 test app not showing data from database

$
0
0

hi everyone,

I would like to know where I am wrong. I created a small dummy app listing movies and thier actors. So I have two model classes, actor and movie. I created the context initializer and added the following to it:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MoviesLibrary.Models
{
    public class MoviesLibraryContextInitializer : DropCreateDatabaseAlways<MovieLibraryContext>
    {
        protected override void Seed(MovieLibraryContext context)
        {
            var films = new List<Movie>
            {
                new Movie {MovieTitle="Crimson Tide", MoviePlot="Supposed Mutiny aboard the USS Alabama pits the Captin against his X.O"},
                new Movie {MovieTitle="UnThinkable", MoviePlot="An Interrogator must make hard decision in service of his country and conscience"},
                new Movie {MovieTitle="Man of Steel", MoviePlot="A Young Man with ExtraOrdinary Powers must come to the aid of his adopted home, earth"},
                new Movie {MovieTitle="The Avengers", MoviePlot="Earth's mightest heros unite to fight a common evil to big for one."}
            };

            films.ForEach(f => context.Movies.Add(f));
            context.SaveChanges();

            var acts = new List<Actor>
            {
                new Actor {ActorName="Denzel Washington", MovieId=1},
                new Actor {ActorName="Henry Cavhill", MovieId=3},
                new Actor {ActorName="Gene Hackman", MovieId=1}
            };
acts.ForEach(a => context.Actor.Add(a));
context.SaveChanges(); } } }

and I also have these models created:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoviesLibrary.Models
{
    public class Movie
    {
        public int MovieId { get; set; }
        public string MovieTitle { get; set; }
        public string MoviePlot { get; set; }
        public ICollection<Actor> Actors { get; set; }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Data;
using System.Web;

namespace MoviesLibrary.Models
{
    public class Actor
    {
        public int ActorId { get; set; }
        public string ActorName { get; set; }
        public int MovieId { get; set; }

        public Movie Movie { get; set; }
    }
}

and this is my context:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace MoviesLibrary.Models
{
    public class MovieLibraryContext : DbContext
    {
        public MovieLibraryContext() : base("DefaultConnection")
        {

        }

        public DbSet<Actor> Actors { get; set; }
        public DbSet<Movie> Movies { get; set; }

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

The controllers I scaffolded and just wanted to see how things would look and nothing. Rather I get an exception with the following words:

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

Additional information: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Now I added sqlite using nuget and setup my web.config like so:

<configSections><section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /><!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections><connectionStrings><add name="DefaultConnection" connectionString="Data Source=C:\Users\codeuser\Documents\MoviesLibrary.db;" providerName="System.Data.SQLite" /></connectionStrings><entityFramework><defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"><parameters><parameter value="v11.0" /></parameters></defaultConnectionFactory><providers><provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /><provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /></providers></entityFramework><system.data><DbProviderFactories><remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /><remove invariant="System.Data.SQLite.EF6" /><add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".Net Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" /></DbProviderFactories></system.data>

so I am lost as to what to do here so any help will be deeply appreciated. Many thanks.


Viewing all articles
Browse latest Browse all 1350

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>