Entity Framework 6 still requires EF5 ProviderName "System.Data.EntityClient - asp.net-mvc

I updated an ASP.NET MVC5 application from EF4 to EF6 and so changed all references from System.Data.EntityClient to System.Data.Entity.Core.EntityClient.
However, the application won't work -- it throws a 500 server error, "connection string doesn't work with this version of EF" -- unless I change the providerName attribute of the connection string back to System.Data.EntityClient!
I'm not even quite sure how it gets a reference to System.Data.EntityClient in the first place -- the app is using all EF6 DLLs.
Perhaps relevant:
I wanted to avoid updating my ObjectContext to a DbContext so I used the available EF 6.x EntityObject Generator to create my entity model. But the generated classes are headed with using System.Data.Entity.Core.EntityClient; as they should be.
The data provider is MySql (provider=MySql.Data.MySqlClient;), using MySQL Connector 6.9.6.

Related

migrate database from one MVC project to another

I am using Visual Studio 2013. Unfortunately I am facing some problems with my MVC project. So I created a new project and I need to fetch database to my new project but can't figure out how to fetch database. I am using data first approach, entity framework and IIS Express localhost.
Update:
I copied connection string from web.config of old project and pasted it over new project's connection string.(Note I first created ado.net entity data model in new project and then pasted string over its connection string).
Now in server explorer window > data connections my Entities connection has changed to defaultconnection and I get exception The underlying provider failed on Open on executing query of new projects database. But I am unable to fetch old database tables.
Your DBContext likely has the name of the database connection in one of it's constructors.
This corresponds to the name of a connection string the web.config.
So move that configuration to your new web config and make sure your new DbContext references the correct name.

Using Entity Framework to query external DB without defining an edmx file

I have the following:-
Asp.net mvc5 web application.
Entity framework version 6.
Now I have mapped the sql server tables inside my asp.net mvc5 using the ado.net entity framework , which created an edmx file.
But now I want to query an external database to retrieve some info from it, I know that I can map the external DB and create another edmx file inside my application. but I do not want to depend my application on the external DB , because the external DB might be replaced by our company in the future.
So is there a way to query external DB using EF ? i tried using DbSet.SqlQuery but seems I can only query my own database with it.
Can anyone advice on this please

How can remove connectionstring from webconfig?

I have a project that has 3 layers.
1)Interface (It is an MVC project with View and Controller)
2)BI (It is a class library project)
3)DAL (It Is A class library that work with Entity Framework DataBase First)
My Problem :
There is a connection string in webconfig of the first project(MVC). But I want remove it. then the other layers should use of DAL Connection Strings.
But when I delete the connection string from that it cant connect and work with DB !!
I remember when I was working with ASP.NET and Linq to sql it was posible.
Please help me.
Once deployed, the only configuration that will be available will be the web.config of your MVC project. Instead of removing the connection string you could just encrypt it.
ASP.NET Connection String Encryption / Protection
Programmatically encrypting a config-file in .NET
http://msdn.microsoft.com/en-us/library/89211k9b.aspx
Personally I'm using a mechanism based on that blog post. I have an administrative api call on my web application to send the information that must be encrypted.
- http://weblogs.asp.net/sukumarraju/archive/2009/09/28/encrypt-and-decrypt-connectionstring-section-in-web-config.aspx

MVC3 EF4 POCO Repository/UnitOfWork Connection Error

I implemented the T4 Repository/ Unit of Work templates by Gil Fink for use in a project I am working on, my first full scale project using MVC. I am, however, getting an error I wasn't getting before, and I can't track it down. I don't know if it's something with the templates, or just a setting somewhere I have set wrong, but I am at a lose right now. I was hoping someone would be able to shed some light on the situation.
Here's my framework setup:
MVC 3 Beta
SQL Server 2008 R2
Ninject v2.1.0.76
EF4 POCO
3 projects in the solution: Data, Entities and the MVC app.
I am doing a DB first design, and using EF to create the POCO classes, via Microsoft's ADO.NET POCO Entity Generator. I then use the T4 tool to create the repository and unit of work patterns. With that setup, and all the classes and repositories generated, I implement it into the MVC app using Ninject for DI. I am using the MVC 2 method using a Controller Factory at this point, with plans to later change it to the IDependencyResolver method.
When I use a hard-coded Mock repository, the application works as it should, however when I change it to use the IRepository binding, I get the following error:
"The supplied connection is not valid because it contains insufficient mapping or metadata information.
Parameter name: connection"
This indicates to me that the connection string for EF to connection to the DB is incorrect, however it is the default string generated by the ADO.NET Entity Data Model template. Perhaps it is also something with the .edmx settings.
Here is my connection string (using the handy Nerd Dinner database layout)
<add name="NerdDinnerEntities"
connectionString="metadata=
res://*/Model1.csdl|
res://*/Model1.ssdl|
res://*/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=Wayne;Initial Catalog=NerdDinner;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
Anyone with any thoughts/ hints, etc, I would be extremely appreciative.
Edit: here's the link for the T4 template I'm using:
Repository and Unit of Work T4 Template for Entity Framework
Edit2:
The error is something to do with home I'm using DI with Unit Of Work. when I remove DI, and manually have the dependencies in the controllers, it works. When I try to implement DI, it breaks.
res://*/Model1.csdl|
That * is a wildcard that says to EF "scan all the assemblies for the resource". Chances are this scan isn't finding the assembly for whatever reason.
Change * to your assembly name:
res://My.Assembly.Name/Model1.csdl|
If you are using NuGet to install your Ninject dependency, it likes to set up your DI bindings in NinjectWebCommon.cs. If loading your DI bindings requires an Entity Framework context to be instantiated, this happens too early in the application lifecycle and the application can't interpret the connection string properly.
If you think this is may be what's happening to you, see my answer here for more information.

How do i get my Windows Azure Worker Role to connect to my Ado.NEt Entity-based db

I've built a backend in ASP.NET MVC2 which has an underlying ADO.NET Entity-based Database.
In the MVC Backend, I call my database entities, i.e.:
Entities entities = new Entities();
...and that all works fine.
Unforutnetly, in my Azure/mvc2 project, My worker role makes the azure project throw weird exceptions:
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
Any ideas ladies and gentlemen?
Solved it myself - it was a PEBKAC issue.
Had to manually set the configuration string in the Worker role's App.config (Copypasted from from the ASP/NET MVC2 Project's Web.config).
All works well now.

Resources