Using LocalDB in ASP.NET MVC Application with EntityFramework 6


At times we resort to the use of LocalDB, which in definition is a light weight version of the SQL Server Express, which loads itself on demand (i.e., whenever the application tries to read data using SQLConnection or through EntityFramework etc.,).  The db itself can be created by right clicking on the App_Data folder and selecting Add->SQL Server database option from Visual Studio Solution Explorer.  Once created the .mdf file resides in the App_Data folder and can be accessed via the Server Explorer (which acts as the conduit) to perform mundane db operations such as create/alter table, open query window etc.,

When we employ EF as the ORM to access data, it doesnt work as straight forward as it does with SQL Server based backend options.  One common error that you may see is the below error (as given in the screenshot):

“The Entity Framework provider type ‘System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6’ registered in the application config file for the ADO.NET provider with invariant name ‘System.Data.SQLite.EF6’ could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.”

Eferror1

The error occurs due to the presence of the below highlighted XML in the EntityFramework (Click on the image to view in full screen):

EFWrongConfElement1

Remove the below highlighted entries and make sure that it looks like the below one:

EFElement

Also, your connection string should like :

EFConString

In addition, make sure that you have the “System.Data.SqLite EF6” Nuget Package installed as well.  To verify if you have it, open up the Packages.Config and you should see an entry like the one given below :

<package id="System.Data.SQLite.EF6" version="1.0.99.0" targetFramework="net451" />

 

1,001 total views, 1 views today

0 votes

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha *